From bd6db12aaeecbc4f76462b4016c7e74e43d532f3 Mon Sep 17 00:00:00 2001
From: zhangqiumiao <zhangqiumiao1@huawei.com>
Date: Tue, 10 Nov 2020 02:10:57 -0500
Subject: [PATCH] add a test case to parse code93 in option_unittest

---
 common/tests/option_unittest.c | 71 ++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)

diff --git a/common/tests/option_unittest.c b/common/tests/option_unittest.c
index 600ebe6..688762d 100644
--- a/common/tests/option_unittest.c
+++ b/common/tests/option_unittest.c
@@ -213,6 +213,76 @@ ATF_TC_BODY(parse_X, tc)
     }
 }
 
+ATF_TC(parse_code93_option);
+
+ATF_TC_HEAD(parse_code93_option, tc)
+{
+    atf_tc_set_md_var(tc, "descr",
+                      "Verify that code93 can be parsed.");
+}
+
+ATF_TC_BODY(parse_code93_option, tc)
+{
+    struct option *option;
+    unsigned code;
+    unsigned char bad_data[32*1024];
+    unsigned char good_data1[] = { 0,0 };
+    unsigned char good_data2[] = { 0,7 };
+    unsigned char good_data3[] = { 0,11 };
+    int emit_commas = 1;
+    int emit_quotes = 1;
+    const char *output_buf;
+
+    /* Initialize whole thing to non-printable chars */
+    memset(bad_data, 0x1f, sizeof(bad_data));
+
+    initialize_common_option_spaces();
+
+    /* We'll use pxe-system-type and it happens to be format Sa */
+    code = 93;
+    option = NULL;
+    if (!option_code_hash_lookup(&option, dhcp_universe.code_hash,
+                                 &code, 0, MDL)) {
+            atf_tc_fail("can't find option %d", code);
+    }
+
+    if (option == NULL) {
+            atf_tc_fail("option is NULL");
+    }
+
+    /* First we will try a good value we know should fit. */
+    output_buf = pretty_print_option (option, good_data1, sizeof(good_data1),
+                                      emit_commas, emit_quotes);
+
+    /* Make sure we get what we expect */
+    if (!output_buf || strcmp(output_buf, "0")) {
+            atf_tc_fail("pretty_print_option 1 did not return \"<error>\"");
+    }
+    
+    output_buf = pretty_print_option (option, good_data2, sizeof(good_data3),
+                                      emit_commas, emit_quotes);
+    /* Make sure we get what we expect */
+    if (!output_buf || strcmp(output_buf, "7")) {
+            atf_tc_fail("pretty_print_option 2 did not return \"<error>\"");
+    }
+
+    output_buf = pretty_print_option (option, good_data3, sizeof(good_data3),
+                                      emit_commas, emit_quotes);
+    /* Make sure we get what we expect */
+    if (!output_buf || strcmp(output_buf, "11")) {
+            atf_tc_fail("pretty_print_option 3 did not return \"<error>\"");
+    }
+
+    /* Now we'll try a data value that's too large */
+    output_buf = pretty_print_option (option, bad_data, sizeof(bad_data),
+                                      emit_commas, emit_quotes);
+
+    /* Make sure we safely get an error */
+    if (!output_buf || strcmp(output_buf, "<error>")) {
+            atf_tc_fail("pretty_print_option did not return \"<error>\"");
+    }
+}
+
 /* This macro defines main() method that will call specified
    test cases. tp and simple_test_case names can be whatever you want
    as long as it is a valid variable identifier. */
@@ -221,6 +291,7 @@ ATF_TP_ADD_TCS(tp)
     ATF_TP_ADD_TC(tp, option_refcnt);
     ATF_TP_ADD_TC(tp, pretty_print_option);
     ATF_TP_ADD_TC(tp, parse_X);
+    ATF_TP_ADD_TC(tp, parse_code93_option);
 
     return (atf_no_error());
 }
-- 
2.23.0

