diff --git a/test/misc/streq.cpp b/test/misc/streq.cpp deleted file mode 100644 index 19428cfa..00000000 --- a/test/misc/streq.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// TEST : {"cmd": "./go streq"} - -#include - -#include -#include -#include - -#include - -using namespace openvpn; - -void test(const std::string& s1, const std::string& s2, const bool should_eq) -{ - const bool neq = crypto::str_neq(s1, s2); - OPENVPN_LOG("'" << s1 << "' cmp '" << s2 << "' " << (neq ? "NEQ" : "EQ")); - if (neq == should_eq) - throw Exception("fail"); -} - -void test_logic() -{ - test("", "", true); - test("x", "", false); - test("", "x", false); - test("foo", "foo", true); - test("foobar", "foo", false); - test("foo", "foobar", false); -} - -void test_timing() -{ - size_t count = 0; - for (size_t i = 0; i < 1000000000; ++i) - count += crypto::str_neq("foobarxxx", "foobar"); - OPENVPN_LOG(count); -} - -int main(int /*argc*/, char* /*argv*/[]) -{ - try { - test_logic(); - //test_timing(); - } - catch (const std::exception& e) - { - std::cerr << "Exception: " << e.what() << std::endl; - return 1; - } - return 0; -} diff --git a/test/unittests/test_streq.cpp b/test/unittests/test_streq.cpp new file mode 100644 index 00000000..5c7ec5d0 --- /dev/null +++ b/test/unittests/test_streq.cpp @@ -0,0 +1,31 @@ +#include "test_common.h" +#include + +#include +#include + +#include + +using namespace openvpn; + +void test(const std::string &s1, const std::string &s2, const bool should_eq) { + const bool neq = crypto::str_neq(s1, s2); + //OPENVPN_LOG("'" << s1 << "' cmp '" << s2 << "' " << (neq ? "NEQ" : "EQ")); + ASSERT_NE(neq, should_eq); +} + +TEST(misc, streq) { + test("", "", true); + test("x", "", false); + test("", "x", false); + test("foo", "foo", true); + test("foobar", "foo", false); + test("foo", "foobar", false); +} + +void test_timing() { + size_t count = 0; + for (size_t i = 0; i < 1000000000; ++i) + count += crypto::str_neq("foobarxxx", "foobar"); + OPENVPN_LOG(count); +} \ No newline at end of file