]> mj.ucw.cz Git - libucw.git/commitdiff
xtypes: updated tests
authorRobert Kessl <kesslr@centrum.cz>
Tue, 22 Jul 2014 13:15:40 +0000 (15:15 +0200)
committerRobert Kessl <kesslr@centrum.cz>
Tue, 22 Jul 2014 13:15:40 +0000 (15:15 +0200)
ucw/xtypes-test.c
ucw/xtypes-test.t [new file with mode: 0644]

index 75e436b5f2717aa350452d61fd2e03c8d9d4afdc..bd7411b1f33acfd7c0da586ec5bc612e3be285c1 100644 (file)
@@ -19,7 +19,7 @@
 
 static void test_size_correct(struct fastbuf *out)
 {
-  const char *size_strs[] = {
+  static const char *size_strs[] = {
     "4",
     "4KB",
     "4MB",
@@ -28,7 +28,7 @@ static void test_size_correct(struct fastbuf *out)
     NULL
   };
 
-  u64 size_parsed[] = {
+  static u64 size_parsed[] = {
     4LLU,
     4 * 1024LLU,
     4 * 1024LLU * 1024LLU,
@@ -42,10 +42,10 @@ static void test_size_correct(struct fastbuf *out)
   while(size_strs[i] != NULL) {
     u64 result;
     const char *parse_err = xt_size.parse(size_strs[i], &result, pool);
-    if(parse_err) {
-      abort();
-    }
+
+    ASSERT_MSG(parse_err == NULL, "Unexpected error in xt_size.parse");
     ASSERT_MSG(size_parsed[i] == result, "xt_size.parse parsed an incorrect value.");
+
     const char *result_str = xt_size.format(&result, i | SIZE_UNITS_FIXED, pool);
     bprintf(out, "%s %s\n", size_strs[i], result_str);
 
@@ -57,7 +57,7 @@ static void test_size_correct(struct fastbuf *out)
 
 static void test_size_parse_errors(struct fastbuf *out)
 {
-  const char *size_strs[] = {
+  static const char *size_strs[] = {
     "1X",
     "KB",
     "\0",
@@ -82,6 +82,38 @@ static void test_size_parse_errors(struct fastbuf *out)
   mp_delete(pool);
 }
 
+static void test_bool_correct(struct fastbuf *out UNUSED)
+{
+  static const char *bool_strs[] = {
+    "0",
+    "1",
+    "false",
+    "true",
+    NULL
+  };
+
+  static bool bool_parsed[] = {
+    false,
+    true,
+    false,
+    true
+  };
+
+  struct mempool *pool = mp_new(4096);
+  uint i = 0;
+
+  while(bool_strs[i] != NULL) {
+    bool result;
+    const char *err_str = xt_bool.parse(bool_strs[i], &result, pool);
+    ASSERT_MSG(err_str == NULL, "Unexpected error in xt_bool.parse.");
+    ASSERT_MSG(bool_parsed[i] == result, "xt_bool.parse parsed an incorrect value.");
+    bprintf(out, "%s %s\n", bool_strs[i], result ? "true" : "false");
+    i++;
+  }
+
+  mp_delete(pool);
+}
+
 int main(void)
 {
   struct fastbuf *out;
@@ -89,7 +121,7 @@ int main(void)
 
   test_size_correct(out);
   test_size_parse_errors(out);
-
+  test_bool_correct(out);
   bclose(out);
 
   return 0;
diff --git a/ucw/xtypes-test.t b/ucw/xtypes-test.t
new file mode 100644 (file)
index 0000000..41768fb
--- /dev/null
@@ -0,0 +1,15 @@
+Run: ../obj/ucw/xtypes-test
+Out <<EOF
+4 4
+4KB 4KB
+4MB 4MB
+4GB 4GB
+4TB 4TB
+xt_size.parse error: 'Invalid format of size: '1X'.'.
+xt_size.parse error: 'Invalid value of size: 'KB'.'.
+xt_size.parse error: 'Invalid value of size: ''.'.
+0 false
+1 true
+false false
+true true
+EOF