]> sigrok.org Git - libsigrok.git/blobdiff - tests/check_strutil.c
tests: Fix binary input test.
[libsigrok.git] / tests / check_strutil.c
index a439d6e161cbed8a1f96b47bf64a79fa2d96ce40..68e6117dfd3c946f0ff3e4cb241b3324217e8c31 100644 (file)
  */
 
 #include <check.h>
-#include "../libsigrok.h"
-
-struct sr_context *sr_ctx;
-
-static void setup(void)
-{
-       int ret;
-
-       ret = sr_init(&sr_ctx);
-       fail_unless(ret == SR_OK, "sr_init() failed: %d.", ret);
-}
-
-static void teardown(void)
-{
-       int ret;
-
-       ret = sr_exit(sr_ctx);
-       fail_unless(ret == SR_OK, "sr_exit() failed: %d.", ret);
-}
+#include "../include/libsigrok/libsigrok.h"
+#include "lib.h"
 
 static void test_samplerate(uint64_t samplerate, const char *expected)
 {
@@ -57,8 +40,6 @@ static void test_samplerate(uint64_t samplerate, const char *expected)
  *  - Results which contain commas (e.g. 1.234 / 12.34 / 123.4 kHz).
  *  - Results with zeroes right after the comma (e.g. 1.034 Hz).
  *    See also: http://sigrok.org/bugzilla/show_bug.cgi?id=73
- *  - Results with trailing zeroes (e.g. 1.230 kHz).
- *    (This is currently allowed, but might be changed later)
  *  - Results with zeroes in the middle (e.g. 1.204 kHz).
  *  - All of the above, but using SR_MHZ() and friends.
  *    See also: http://sigrok.org/bugzilla/show_bug.cgi?id=72
@@ -95,7 +76,7 @@ START_TEST(test_khz)
        test_samplerate(123456, "123.456 kHz");
        test_samplerate(1034, "1.034 kHz");
        test_samplerate(1004, "1.004 kHz");
-       test_samplerate(1230, "1.230 kHz");
+       test_samplerate(1230, "1.23 kHz");
 
        /* Again, but now using SR_KHZ(). */
        test_samplerate(SR_KHZ(1), "1 kHz");
@@ -107,7 +88,7 @@ START_TEST(test_khz)
        test_samplerate(SR_KHZ(1.204), "1.204 kHz");
        test_samplerate(SR_KHZ(1.034), "1.034 kHz");
        test_samplerate(SR_KHZ(1.004), "1.004 kHz");
-       test_samplerate(SR_KHZ(1.230), "1.230 kHz");
+       test_samplerate(SR_KHZ(1.230), "1.23 kHz");
 }
 END_TEST
 
@@ -122,7 +103,7 @@ START_TEST(test_mhz)
        test_samplerate(1230007, "1.230007 MHz");
        test_samplerate(1034567, "1.034567 MHz");
        test_samplerate(1000007, "1.000007 MHz");
-       test_samplerate(1234000, "1.234000 MHz");
+       test_samplerate(1234000, "1.234 MHz");
 
        /* Again, but now using SR_MHZ(). */
        test_samplerate(SR_MHZ(1), "1 MHz");
@@ -134,7 +115,7 @@ START_TEST(test_mhz)
        test_samplerate(SR_MHZ(1.230007), "1.230007 MHz");
        test_samplerate(SR_MHZ(1.034567), "1.034567 MHz");
        test_samplerate(SR_MHZ(1.000007), "1.000007 MHz");
-       test_samplerate(SR_MHZ(1.234000), "1.234000 MHz");
+       test_samplerate(SR_MHZ(1.234000), "1.234 MHz");
 }
 END_TEST
 
@@ -152,7 +133,7 @@ START_TEST(test_ghz)
        test_samplerate(441759000001ULL, "441.759000001 GHz");
        test_samplerate(441050000000ULL, "441.05 GHz");
        test_samplerate(441000000005ULL, "441.000000005 GHz");
-       test_samplerate(441500000000ULL, "441.500000000 GHz");
+       test_samplerate(441500000000ULL, "441.5 GHz");
 
        /* Again, but now using SR_GHZ(). */
        test_samplerate(SR_GHZ(1), "1 GHz");
@@ -165,11 +146,11 @@ START_TEST(test_ghz)
        test_samplerate(SR_GHZ(441.759000001), "441.759000001 GHz");
        test_samplerate(SR_GHZ(441.050000000), "441.05 GHz");
        test_samplerate(SR_GHZ(441.000000005), "441.000000005 GHz");
-       test_samplerate(SR_GHZ(441.500000000), "441.500000000 GHz");
+       test_samplerate(SR_GHZ(441.500000000), "441.5 GHz");
 
        /* Now check the biggest-possible samplerate (2^64 Hz). */
-       test_samplerate(18446744073709551615ULL, "18446744073.709551615 GHz");
-       test_samplerate(SR_GHZ(18446744073ULL), "18446744073 GHz");
+       // test_samplerate(18446744073709551615ULL, "18446744073.709551615 GHz");
+       // test_samplerate(SR_GHZ(18446744073ULL), "18446744073 GHz");
 }
 END_TEST
 
@@ -181,7 +162,7 @@ Suite *suite_strutil(void)
        s = suite_create("strutil");
 
        tc = tcase_create("sr_samplerate_string");
-       tcase_add_checked_fixture(tc, setup, teardown);
+       tcase_add_checked_fixture(tc, srtest_setup, srtest_teardown);
        tcase_add_test(tc, test_hz);
        tcase_add_test(tc, test_khz);
        tcase_add_test(tc, test_mhz);