]> mj.ucw.cz Git - libucw.git/commitdiff
tableprinter&xtypes: assert changed to die in tests, fix of timestamp parsing
authorRobert Kessl <kesslr@centrum.cz>
Wed, 23 Jul 2014 12:52:41 +0000 (14:52 +0200)
committerRobert Kessl <kesslr@centrum.cz>
Wed, 23 Jul 2014 12:52:41 +0000 (14:52 +0200)
ucw/table-types.c
ucw/xtypes-test.c
ucw/xtypes-test.t

index 891f600434dcc598f8dcca9399fc23738e2b453c..063760b705314fe2dd9b65144563031542805ca4 100644 (file)
@@ -174,14 +174,14 @@ static const char *xt_timestamp_parse(const char *str, void *dest, struct mempoo
     return NULL;
   }
 
-
   struct tm parsed_time;
-  //"%Y-%m-%d %H:%M:%S"
-  //"%F %T"
   parse_end = strptime(str, "%F %T", &parsed_time);
   if(parse_end == NULL) {
     return mp_printf(pool, "Invalid value of timestamp: '%s'.", str);
   }
+  if(*parse_end != 0) {
+    return mp_printf(pool, "Invalid value of timestamp: '%s'.", str);
+  }
 
   time_t tmp_time = mktime(&parsed_time);
   *(u64*)dest = (u64) tmp_time;
index 9ed3461182017dfcc58a1e4b400832bb3677bc7b..ae89b154c9683165b28dbe2394922fa557d9a287 100644 (file)
@@ -42,8 +42,12 @@ static void test_size_parse_correct(struct fastbuf *out)
     u64 result;
     const char *parse_err = xt_size.parse(size_strs[i], &result, pool);
 
-    ASSERT_MSG(parse_err == NULL, "Unexpected error in xt_size.parse");
-    ASSERT_MSG(size_parsed[i] == result, "xt_size.parse parsed an incorrect value.");
+    if(parse_err != NULL) {
+      die("Unexpected error in xt_size.parse");
+    }
+    if(size_parsed[i] != result) {
+      die("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);
@@ -104,8 +108,12 @@ static void test_bool_parse_correct(struct fastbuf *out)
   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 %s", err_str);
-    ASSERT_MSG(bool_parsed[i] == result, "xt_bool.parse parsed an incorrect value.");
+    if(err_str != NULL) {
+      die("Unexpected error in xt_bool.parse %s", err_str);
+    }
+    if(bool_parsed[i] != result) {
+      die("xt_bool.parse parsed an incorrect value.");
+    }
     bprintf(out, "%s %s\n", bool_strs[i], result ? "true" : "false");
     i++;
   }
@@ -132,8 +140,13 @@ static void test_timestamp_parse_correct(struct fastbuf *out)
   while(timestamp_strs[i]) {
     u64 result;
     const char *err_str = xt_timestamp.parse(timestamp_strs[i], &result, pool);
-    ASSERT_MSG(err_str == NULL, "Unexpected error in xt_size.parse: %s", err_str);
-    ASSERT_MSG(timestamp_parsed[i] == result, "Expected: %" PRIu64 " but got %" PRIu64, timestamp_parsed[i], result);
+    if(err_str != NULL) {
+      die("Unexpected error in xt_timestamp.parse: %s", err_str);
+    }
+    if(timestamp_parsed[i] != result) {
+      die("Expected: %" PRIu64 " but got %" PRIu64, timestamp_parsed[i], result);
+    }
+
     bprintf(out, "%" PRIu64 " %" PRIu64 "\n", timestamp_parsed[i], result);
 
     i++;
@@ -148,6 +161,7 @@ static void test_timestamp_parse_errors(struct fastbuf *out)
     "1403685533X",
     "2014X-06-25 08:38:53",
     "2X014-06-25 08:38:53",
+    "2014-06-25 08:38:53X",
     "X1403685533",
     NULL
   };
@@ -165,10 +179,6 @@ static void test_timestamp_parse_errors(struct fastbuf *out)
       bprintf(out, "xt_timestamp.parse error: '%s'.\n", err_str);
     }
 
-    // ASSERT_MSG(err_str != NULL,
-    //bprintf(out, "%" PRIu64 " %" PRIu64 "\n", timestamp_parsed[i], result);
-    //ASSERT_MSG(timestamp_parsed[i] == result, "Expected: %" PRIu64 " but got %" PRIu64, timestamp_parsed[i], result);
-
     i++;
   }
 
index 467754758d8aebc52df5a75d7c4e93105f8c0143..396bda3aa8d854e2175c3cb4dcecc31f9aec29fb 100644 (file)
@@ -17,5 +17,6 @@ true true
 xt_timestamp.parse error: 'Invalid value of timestamp: '1403685533X'.'.
 xt_timestamp.parse error: 'Invalid value of timestamp: '2014X-06-25 08:38:53'.'.
 xt_timestamp.parse error: 'Invalid value of timestamp: '2X014-06-25 08:38:53'.'.
+xt_timestamp.parse error: 'Invalid value of timestamp: '2014-06-25 08:38:53X'.'.
 xt_timestamp.parse error: 'Invalid value of timestamp: 'X1403685533'.'.
 EOF