diff --git a/cpp/CMakeLists-cascara.txt b/cpp/CMakeLists-cascara.txt new file mode 100644 index 0000000..01f3d01 --- /dev/null +++ b/cpp/CMakeLists-cascara.txt @@ -0,0 +1,23 @@ +include(ExternalProject) +ExternalProject_Add( + cascara + + GIT_REPOSITORY "${GITBASE}/mabels/cascara" + GIT_TAG "master" + + UPDATE_COMMAND "" + + SOURCE_DIR "${CMAKE_SOURCE_DIR}/3rdparty/cascara" + CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -DARCHIVE_INSTALL_DIR= -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX:PATH= ../.. + + #BUILD_COMMAND "" + #INSTALL_COMMAND "" + TEST_COMMAND "" +) + +ExternalProject_Get_Property(cascara install_dir) +include_directories(${install_dir}/include) + + +set(cascara_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/3rdparty/cascara/include") +include_directories(${cascara_INCLUDE_DIRS}) diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt index 36dc0ff..c884947 100755 --- a/cpp/CMakeLists.txt +++ b/cpp/CMakeLists.txt @@ -13,9 +13,13 @@ endif() set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -g") +if(NOT GITBASE) + set(GITBASE https://github.com) +endif() + #Only tested with versions 1.55 and 1.56 -find_package(Boost 1.54.0 COMPONENTS system regex coroutine context thread iostreams REQUIRED) +find_package(Boost 1.54.0 COMPONENTS system regex REQUIRED) include_directories(${Boost_INCLUDE_DIR}) if(APPLE) @@ -25,6 +29,9 @@ endif() #include(CMakeLists-easyloggingpp.txt) +include(CMakeLists-cascara.txt) + + #set(SIMPLEWEB_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/3rdparty/Simple-WebSocket-Server") #TODO: add requirement for version 1.0.1g (can it be done in one line?) #find_package(OpenSSL REQUIRED) diff --git a/cpp/test/CMakeLists.txt b/cpp/test/CMakeLists.txt index 954386b..61028c0 100755 --- a/cpp/test/CMakeLists.txt +++ b/cpp/test/CMakeLists.txt @@ -15,7 +15,7 @@ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -g") enable_testing() -find_package(Boost 1.54.0 COMPONENTS system coroutine context iostreams thread regex REQUIRED) +find_package(Boost 1.54.0 COMPONENTS system regex REQUIRED) include_directories(${Boost_INCLUDE_DIR}) find_package(Threads REQUIRED) diff --git a/cpp/test/chai.hpp b/cpp/test/chai.hpp deleted file mode 100644 index ace0af8..0000000 --- a/cpp/test/chai.hpp +++ /dev/null @@ -1,140 +0,0 @@ -#ifndef __chai__ -#define __chai__ - -#include -#include -#include -#include -#include - -namespace Chai { - - class AssertError : public std::exception { - const std::string msg; - public: - AssertError(const char *msg) : msg(msg) {} - ~AssertError() {} - - virtual const char* what() const throw() { - return msg.c_str(); - } - }; - - class Assert { - public: - size_t count = 0; - void isTrue(bool v, const std::string &msg) { - this->isTrue(v, msg.c_str()); - } - void isTrue(bool v, const char *msg = "") { - ++count; - if (!v) { - std::stringstream s2; - s2 << "isTrue got false, "; - s2 << msg; - throw AssertError(s2.str().c_str()); - } - } - void isFalse(bool v, const char *msg = "") { - ++count; - if (v) { - std::stringstream s2; - s2 << "isFalse got true, "; - s2 << msg; - throw AssertError(s2.str().c_str()); - } - } - void equal(const std::string &t1, const char *t2, const char *msg = "") { - this->equal(t1, std::string(t2), msg); - } - void equal(const char *t1, const std::string &t2, const char *msg = "") { - this->equal(std::string(t1), t2, msg); - } - void equal(const char *t1, const char *t2, const char *msg = "") { - this->equal(std::string(t1), std::string(t2), msg); - } - void equal(unsigned char t1, unsigned char t2, const char *msg = "") { - ++count; - if (t1 != t2) { - std::stringstream s2; - s2 << "uchar is not equal "; - s2 << std::hex; - s2 << static_cast(t1) << "==" << static_cast(t2) << ". "; - s2 << msg; - // std::cout << "MSG=>" << msg << std::endl; - throw AssertError(s2.str().c_str()); - } - - } - template void equal(T t1, T t2, const char *msg = "") { - ++count; - if (t1 != t2) { - std::stringstream s2; - s2 << "is not equal "; - s2 << t1 << "==" << t2 << ". "; - s2 << msg; - throw AssertError(s2.str().c_str()); - } - } - static std::string vec_to_string(size_t m, const std::vector &t) { - std::stringstream s2; - s2 << std::hex; - const char *sep = ""; - for (size_t i = 0; i < t.size(); ++i) { - s2 << sep; - if (m == i) { s2 << "["; } - s2 << static_cast(t[i]); - if (m == i) { s2 << "]"; } - sep = " "; - } - return s2.str(); - } - static std::string vec_to_string(size_t m, const std::vector &t) { - std::stringstream s2; - s2 << std::hex; - const char *sep = ""; - for (size_t i = 0; i < t.size(); ++i) { - s2 << sep; - if (m == i) { s2 << "["; } - s2 << static_cast(t[i]); - if (m == i) { s2 << "]"; } - sep = " "; - } - return s2.str(); - } - - template - static std::string vec_to_string(size_t m, const std::vector &t) { - std::stringstream s2; - const char *sep = ""; - for (size_t i = 0; i < t.size(); ++i) { - s2 << sep; - if (m == i) { s2 << "["; } - s2 << t[i]; - if (m == i) { s2 << "]"; } - sep = " "; - } - return s2.str(); - } - - template void deepEqual(std::vector left, std::vector right, const char *msg = "") { - ++count; - std::stringstream s2; - s2 << "array size() missmatch:" << msg << ":" << - Assert::vec_to_string(0, left) << "====" << - Assert::vec_to_string(0, right); - this->equal(left.size(), right.size(), s2.str().c_str()); - for (size_t i = 0; i < left.size(); ++i) { - // std::cout << left[i] << "==" << right[i] << std::endl; - std::stringstream s2; - s2 << msg << "=>"; - s2 << "left:" << Assert::vec_to_string(i, left); - s2 << "====="; - s2 << "right:" << Assert::vec_to_string(i, right); - this->equal(left[i], right[i], s2.str().c_str()); - } - } - }; - static Assert assert; -} -#endif diff --git a/cpp/test/mocha.hpp b/cpp/test/mocha.hpp deleted file mode 100755 index 40b8add..0000000 --- a/cpp/test/mocha.hpp +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef __MOCHA__ -#define __MOCHA__ - -#include -#include -#include "chai.hpp" -#include -#include - -typedef std::function MochaAction; - -static int failCount = 0; -static int okCount = 0; - - -int exit() { - - std::stringstream s2; - s2 << std::dec << "Total " << okCount+failCount - << " Ok " << okCount - << " Fail " << failCount - << " Assertions " << Chai::assert.count; - - std::stringstream cmake; - cmake << "cmake -E cmake_echo_color --"; - if (failCount) { - cmake << "red"; - } else { - cmake << "green"; - } - cmake << " --bold " << "'" << s2.str() << "'"; - auto ret = system(cmake.str().c_str()); - if (ret) { - std::cout << cmake.str() << std::endl; - } - std::cout << std::endl; - std::exit(std::min(failCount, 27)); -} - -static const char *describeContext = ""; -void describe(const char *title, const MochaAction &action) { - std::cout << "Test:" << title << std::endl; - describeContext = title; - (action)(); -} - -void it(const char *title, const MochaAction &action) { - try { - (action)(); - - auto ret = system("cmake -E cmake_echo_color --green --bold --no-newline ' ✓ '"); - if (ret) { std::cout << " FINE "; } - std::cout << describeContext << ":" << title << std::endl; - ++okCount; - } catch (Chai::AssertError &e) { - auto ret = system("cmake -E cmake_echo_color --red --bold --no-newline ' - '"); - if (ret) { std::cout << " FAIL "; } - std::cout << describeContext << ":" << title << " " << e.what() << std::endl; - ++failCount; - } -} - -#endif diff --git a/cpp/test/test_crunchy.cpp b/cpp/test/test_crunchy.cpp index d0f7115..8056beb 100644 --- a/cpp/test/test_crunchy.cpp +++ b/cpp/test/test_crunchy.cpp @@ -1,7 +1,8 @@ #include "../src/crunchy.hpp" -#include "chai.hpp" -#include "mocha.hpp" + +#include +using namespace cascara; using namespace ipaddress; int main(int, char **) { @@ -12,7 +13,7 @@ int main(int, char **) { auto x = Crunchy::from_string("12345678901234567890").unwrap(); auto y = Crunchy::from_string("12345678901234567890").unwrap(); // std::cout << x << ":" << y << std::endl; - Chai::assert.isTrue(x.eq(y)); + assert.isTrue(x.eq(y)); // this.done(); }); @@ -20,7 +21,7 @@ int main(int, char **) { auto x = Crunchy::from_string("12345678901234567890").unwrap(); auto y = Crunchy::from_string("1234567890").unwrap(); // std::cout << x << ":" << y << std::endl; - Chai::assert.isTrue(x.gt(y)); + assert.isTrue(x.gt(y)); // this.done(); }); @@ -28,7 +29,7 @@ int main(int, char **) { auto x = Crunchy::from_string("1234567890").unwrap(); auto y = Crunchy::from_string("12345678901234567890").unwrap(); // std::cout << x << ":" << y << std::endl; - Chai::assert.isTrue(x.lt(y)); + assert.isTrue(x.lt(y)); // this.done(); }); @@ -40,7 +41,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({242, 62}); auto y = Crunchy::from_8bit({42, 2}); - Chai::assert.deepEqual(x.add(y).to_8bit(), {1, 28, 64}); + assert.deepEqual(x.add(y).to_8bit(), {1, 28, 64}); // x.should.eql([242, 62]); // y.should.eql([42, 2]); }); @@ -49,7 +50,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({26, 255, 230, 17}); auto y = Crunchy::from_8bit({42, 34}); - Chai::assert.deepEqual(x.add(y).to_8bit(), {27, 0, 16, 51}); + assert.deepEqual(x.add(y).to_8bit(), {27, 0, 16, 51}); // x, [26, 255, 230, 17]); // y.should.eql([42, 34]); @@ -59,7 +60,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({234, 34}); auto y = Crunchy::from_8bit({255, 255, 230, 17}); - Chai::assert.deepEqual(x.add(y).to_8bit(), {1, 0, 0, 208, 51}); + assert.deepEqual(x.add(y).to_8bit(), {1, 0, 0, 208, 51}); // x.should.eql([234, 34]); // y.should.eql([255, 255, 230, 17]); @@ -69,7 +70,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({255, 255, 255, 255, 255, 255}); auto y = Crunchy::from_8bit({255, 255, 255, 255, 255, 255}); - Chai::assert.deepEqual(x.add(y).to_8bit(), + assert.deepEqual(x.add(y).to_8bit(), {1, 255, 255, 255, 255, 255, 254}); // x.should.eql([255, 255, 255, 255, 255, 255]); @@ -86,7 +87,7 @@ int main(int, char **) { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff - 20, 0xff - 89, 0xff - 145, 0xff - 31}); - Chai::assert.deepEqual(x.add(y).to_8bit(), {31, 164, 255, 175}); + assert.deepEqual(x.add(y).to_8bit(), {31, 164, 255, 175}); // x.should.eql([51, 254, 144, 207]); // y.should.eql([-20, 89, 145, 32]); @@ -101,7 +102,7 @@ int main(int, char **) { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff - 242, 0xff - 61}); auto y = Crunchy::from_8bit({242, 64}); - Chai::assert.deepEqual(x.add(y).to_8bit(), {2}); + assert.deepEqual(x.add(y).to_8bit(), {2}); // x.should.eql([242, 62]); // y.should.eql([-242, 64]); @@ -112,7 +113,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({42, 2}); auto y = Crunchy::from_8bit({242, 62}); - Chai::assert.deepEqual(x.add(y).to_8bit(), {1, 28, 64}); + assert.deepEqual(x.add(y).to_8bit(), {1, 28, 64}); // x, [-42, 2]); // y, [242, 62]); @@ -123,7 +124,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({42, 2}); auto y = Crunchy::from_8bit({42, 0}); - Chai::assert.deepEqual(x.add(y).to_8bit(), {84, 2}); + assert.deepEqual(x.add(y).to_8bit(), {84, 2}); // x, [-42, 2]); // y, [42, 0]); }); @@ -132,7 +133,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({242, 62}); auto y = Crunchy::from_8bit({42, 2}); - Chai::assert.deepEqual(x.add(y).to_8bit(), {1, 28, 64}); + assert.deepEqual(x.add(y).to_8bit(), {1, 28, 64}); // x, [-242, 62]); // y, [-42, 2]); @@ -142,7 +143,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({26, 255, 230, 17}); auto y = Crunchy::from_8bit({0}); - Chai::assert.deepEqual(x.add(y).to_8bit(), {26, 255, 230, 17}); + assert.deepEqual(x.add(y).to_8bit(), {26, 255, 230, 17}); // x, [26, 255, 230, 17]); // y, { 0 }); @@ -152,7 +153,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({0}); auto y = Crunchy::from_8bit({43, 123, 200, 1}); - Chai::assert.deepEqual(x.add(y).to_8bit(), {43, 123, 200, 1}); + assert.deepEqual(x.add(y).to_8bit(), {43, 123, 200, 1}); // x, { 0 }); // y, [43, 123, 200, 1]); @@ -162,7 +163,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({0}); auto y = Crunchy::from_8bit({0}); - Chai::assert.deepEqual(x.add(y).to_8bit(), {0}); + assert.deepEqual(x.add(y).to_8bit(), {0}); // x.should.eql({ 0 }); // y.should.eql({ 0 }); @@ -180,7 +181,7 @@ int main(int, char **) { // console.log(new Date(), x, y); // console.log("addddddd:", new Date(), x, x.toString(), y, y.toString(), // x.add(y).toString()); - Chai::assert.equal(x.add(y).toString(), "24691357812469135781"); + assert.equal(x.add(y).toString(), "24691357812469135781"); // console.log(new Date()); // this.done(); }); @@ -188,42 +189,42 @@ int main(int, char **) { it("Should add numbers, first longer than second", []() { auto x = Crunchy::from_string("12345678901234567890").unwrap(); auto y = Crunchy::from_string("1234567890").unwrap(); - Chai::assert.equal(x.add(y).toString(), "12345678902469135780"); + assert.equal(x.add(y).toString(), "12345678902469135780"); // this.done(); }); it("Should add numbers, second longer than first", []() { auto x = Crunchy::from_string("1234567890").unwrap(); auto y = Crunchy::from_string("12345678901234567890").unwrap(); - Chai::assert.equal(x.add(y).toString(), "12345678902469135780"); + assert.equal(x.add(y).toString(), "12345678902469135780"); // this.done(); }); it("Should add two identical numbers", []() { auto x = Crunchy::from_string("12345678901234567890").unwrap(); auto y = Crunchy::from_string("12345678901234567890").unwrap(); - Chai::assert.equal(x.add(y).toString(), "24691357802469135780"); + assert.equal(x.add(y).toString(), "24691357802469135780"); // this.done(); }); it("Should add zero to number", []() { auto x = Crunchy::from_string("12345678901234567890").unwrap(); auto y = Crunchy::from_string("0").unwrap(); - Chai::assert.equal(x.add(y).toString(), "12345678901234567890"); + assert.equal(x.add(y).toString(), "12345678901234567890"); // this.done(); }); it("Should add number to zero", []() { auto x = Crunchy::from_string("0").unwrap(); auto y = Crunchy::from_string("12345678901234567890").unwrap(); - Chai::assert.equal(x.add(y).toString(), "12345678901234567890"); + assert.equal(x.add(y).toString(), "12345678901234567890"); // this.done(); }); it("Should add two zeros", []() { auto x = Crunchy::from_string("0").unwrap(); auto y = Crunchy::from_string("0").unwrap(); - Chai::assert.equal(x.add(y).toString(), "0"); + assert.equal(x.add(y).toString(), "0"); // this.done(); }); @@ -236,7 +237,7 @@ int main(int, char **) { auto y = Crunchy::from_8bit({17, 241, 123, 250, 42, 2}); // console.log("Should subtract numbers:", x, y, x.sub(y)); - Chai::assert.deepEqual(x.sub(y).to_8bit(), {152, 15, 211, 125, 200, 60}); + assert.deepEqual(x.sub(y).to_8bit(), {152, 15, 211, 125, 200, 60}); // x.to_8bit().should.eql([170, 1, 79, 119, 242, 62]); // y.should.eql([17, 241, 123, 250, 42, 2]); }); @@ -245,7 +246,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({240, 0, 0, 0, 0, 0}); auto y = Crunchy::from_8bit({1}); - Chai::assert.deepEqual(x.sub(y).to_8bit(), + assert.deepEqual(x.sub(y).to_8bit(), {239, 255, 255, 255, 255, 255}); // x.should.eql([240, 0, 0, 0, 0, 0]); @@ -256,7 +257,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({26}); auto y = Crunchy::from_8bit({255}); - Chai::assert.deepEqual(x.sub(y).to_8bit(), + assert.deepEqual(x.sub(y).to_8bit(), {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, @@ -270,7 +271,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({188, 196}); auto y = Crunchy::from_8bit({188, 197}); - Chai::assert.deepEqual(x.sub(y).to_8bit(), + assert.deepEqual(x.sub(y).to_8bit(), {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, @@ -284,7 +285,7 @@ int main(int, char **) { auto y = Crunchy::from_8bit({240, 0, 0, 0, 0, 0}); auto x = Crunchy::from_8bit({1}); // console.log("negative:", x, y, x.sub(y)); - Chai::assert.deepEqual(x.sub(y).to_8bit(), + assert.deepEqual(x.sub(y).to_8bit(), {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, @@ -298,7 +299,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({240, 0, 0, 0, 0, 0}); auto y = Crunchy::from_8bit({1}); - Chai::assert.deepEqual(x.sub(y).to_8bit(), + assert.deepEqual(x.sub(y).to_8bit(), {239, 255, 255, 255, 255, 255}); // x.should.eql([-240, 0, 0, 0, 0, 0]); @@ -309,7 +310,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({240, 0, 0, 0, 0, 0}); auto y = Crunchy::from_8bit({1}); - Chai::assert.deepEqual(x.sub(y).to_8bit(), + assert.deepEqual(x.sub(y).to_8bit(), {239, 255, 255, 255, 255, 255}); // x.should.eql([-240, 0, 0, 0, 0, 0]); @@ -320,7 +321,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({20}); auto y = Crunchy::from_8bit({20}); - Chai::assert.deepEqual(x.sub(y).to_8bit(), {0}); + assert.deepEqual(x.sub(y).to_8bit(), {0}); // x.should.eql({ 20 }); // y.should.eql({ 20 }); @@ -330,7 +331,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({244, 137, 7, 161}); auto y = Crunchy::from_8bit({0}); - Chai::assert.deepEqual(x.sub(y).to_8bit(), {244, 137, 7, 161}); + assert.deepEqual(x.sub(y).to_8bit(), {244, 137, 7, 161}); // x.should.eql([244, 137, 7, 161]); // y.should.eql({ 0 }); @@ -340,7 +341,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({0}); auto y = Crunchy::from_8bit({0}); - Chai::assert.deepEqual(x.sub(y).to_8bit(), {0}); + assert.deepEqual(x.sub(y).to_8bit(), {0}); // x.should.eql({ 0 }); // y.should.eql({ 0 }); @@ -350,7 +351,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({0}); auto y = Crunchy::from_8bit({15}); - Chai::assert.deepEqual(x.sub(y).to_8bit(), + assert.deepEqual(x.sub(y).to_8bit(), {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, @@ -368,14 +369,14 @@ int main(int, char **) { auto x = Crunchy::from_8bit({162, 51, 95}); auto y = Crunchy::from_8bit({42, 18, 204}); - Chai::assert.deepEqual(x.mul(y).to_8bit(), {26, 168, 86, 115, 157, 180}); + assert.deepEqual(x.mul(y).to_8bit(), {26, 168, 86, 115, 157, 180}); }); it("Should multiply numbers", []() { auto x = Crunchy::from_8bit({255, 65, 34, 51, 95}); auto y = Crunchy::from_8bit({42, 18, 204}); - Chai::assert.deepEqual(x.mul(y).to_8bit(), + assert.deepEqual(x.mul(y).to_8bit(), {41, 243, 109, 152, 188, 115, 157, 180}); }); @@ -383,7 +384,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({255, 255, 255, 255}); auto y = Crunchy::from_8bit({255, 255, 255, 255}); - Chai::assert.deepEqual(x.mul(y).to_8bit(), + assert.deepEqual(x.mul(y).to_8bit(), {255, 255, 255, 254, 0, 0, 0, 1}); }); @@ -391,7 +392,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({77, 242, 62}); auto y = Crunchy::from_8bit({42, 2, 113, 43, 57, 65}); - Chai::assert.deepEqual(x.mul(y).to_8bit(), + assert.deepEqual(x.mul(y).to_8bit(), {12, 202, 124, 133, 146, 125, 36, 79, 190}); }); @@ -399,7 +400,7 @@ int main(int, char **) { auto x = Crunchy::from_8bit({255, 17, 162, 62}); auto y = Crunchy::from_8bit({255, 17, 162, 62}); - Chai::assert.deepEqual(x.mul(y).to_8bit(), + assert.deepEqual(x.mul(y).to_8bit(), {254, 36, 34, 110, 119, 14, 135, 4}); }); @@ -407,28 +408,28 @@ int main(int, char **) { auto x = Crunchy::from_8bit({162, 51, 95}); auto y = Crunchy::from_8bit({42, 18, 204}); - Chai::assert.deepEqual(x.mul(y).to_8bit(), {26, 168, 86, 115, 157, 180}); + assert.deepEqual(x.mul(y).to_8bit(), {26, 168, 86, 115, 157, 180}); }); it("Should multiply by zero", []() { auto x = Crunchy::from_8bit({77, 242, 62}); auto y = Crunchy::from_8bit({0}); - Chai::assert.deepEqual(x.mul(y).to_8bit(), {0}); + assert.deepEqual(x.mul(y).to_8bit(), {0}); }); it("Should multiply zero by number", []() { auto x = Crunchy::from_8bit({0}); auto y = Crunchy::from_8bit({77, 242, 62}); - Chai::assert.deepEqual(x.mul(y).to_8bit(), {0}); + assert.deepEqual(x.mul(y).to_8bit(), {0}); }); it("Should multiply zeros", []() { auto x = Crunchy::from_8bit({0}); auto y = Crunchy::from_8bit({0}); - Chai::assert.deepEqual(x.mul(y).to_8bit(), {0}); + assert.deepEqual(x.mul(y).to_8bit(), {0}); }); }); @@ -439,49 +440,49 @@ int main(int, char **) { auto x = Crunchy::from_8bit({52, 155, 168, 23, 6, 85}); auto y = Crunchy::from_8bit({19, 26, 247}); - Chai::assert.deepEqual(x.div(y).to_8bit(), {2, 192, 234, 136}); + assert.deepEqual(x.div(y).to_8bit(), {2, 192, 234, 136}); }); it("Should divide by one", []() { auto x = Crunchy::from_8bit({15, 127, 73, 1}); auto y = Crunchy::from_8bit({1}); - Chai::assert.deepEqual(x.div(y).to_8bit(), {15, 127, 73, 1}); + assert.deepEqual(x.div(y).to_8bit(), {15, 127, 73, 1}); }); it("Should divide by self", []() { auto x = Crunchy::from_8bit({15, 127, 73, 1}); auto y = Crunchy::from_8bit({15, 127, 73, 1}); - Chai::assert.deepEqual(x.div(y).to_8bit(), {1}); + assert.deepEqual(x.div(y).to_8bit(), {1}); }); it("Should divide negative number", []() { auto x = Crunchy::from_8bit({170, 153, 136}); auto y = Crunchy::from_8bit({17, 68}); - Chai::assert.deepEqual(x.div(y).to_8bit(), {9, 225}); + assert.deepEqual(x.div(y).to_8bit(), {9, 225}); }); it("Should divide by negative number", []() { auto x = Crunchy::from_8bit({170, 153, 136, 119, 102, 85}); auto y = Crunchy::from_8bit({17, 68}); - Chai::assert.deepEqual(x.div(y).to_8bit(), {9, 225, 129, 255, 9}); + assert.deepEqual(x.div(y).to_8bit(), {9, 225, 129, 255, 9}); }); it("Should divide two negative numbers", []() { auto x = Crunchy::from_8bit({52, 155, 168, 23, 6, 85}); auto y = Crunchy::from_8bit({19, 26, 247}); - Chai::assert.deepEqual(x.div(y).to_8bit(), {2, 192, 234, 136}); + assert.deepEqual(x.div(y).to_8bit(), {2, 192, 234, 136}); }); it("Should divide zero", []() { auto x = Crunchy::from_8bit({0}); auto y = Crunchy::from_8bit({17, 68}); - Chai::assert.deepEqual(x.div(y).to_8bit(), {0}); + assert.deepEqual(x.div(y).to_8bit(), {0}); }); it("Shouldn't divide by zero", []() { @@ -489,10 +490,10 @@ int main(int, char **) { auto y = Crunchy::from_8bit({0}); try { x.div(y); - Chai::assert.isTrue(false, "never should touched"); + assert.isTrue(false, "never should touched"); } catch (std::overflow_error e) { } - // Chai::assert.isNotOk(x.div(y)); + // assert.isNotOk(x.div(y)); }); it("Shouldn't divide zero by zero", []() { @@ -500,7 +501,7 @@ int main(int, char **) { auto y = Crunchy::from_8bit({0}); try { x.div(y); - Chai::assert.isTrue(false, "never should touched"); + assert.isTrue(false, "never should touched"); } catch (std::overflow_error e) { } }); @@ -513,46 +514,46 @@ int main(int, char **) { auto x = Crunchy::from_8bit({52, 155, 168, 23, 6, 85}), y = Crunchy::from_8bit({19, 26, 247}); - Chai::assert.deepEqual(x.mod(y).to_8bit(), {10, 237, 29}); + assert.deepEqual(x.mod(y).to_8bit(), {10, 237, 29}); }); it("Should calculate modulo of number smaller than modulus", []() { auto x = Crunchy::from_8bit({1, 0}), y = Crunchy::from_8bit({1, 241}); - Chai::assert.deepEqual(x.mod(y).to_8bit(), {1, 0}); + assert.deepEqual(x.mod(y).to_8bit(), {1, 0}); }); it("Should calculate modulo of modulus", []() { auto x = Crunchy::from_8bit({1, 241}), y = Crunchy::from_8bit({1, 241}); - Chai::assert.deepEqual(x.mod(y).to_8bit(), {0}); + assert.deepEqual(x.mod(y).to_8bit(), {0}); }); it("Should calculate modulo of zero", []() { auto x = Crunchy::from_8bit({0}), y = Crunchy::from_8bit({1, 241}); - Chai::assert.deepEqual(x.mod(y).to_8bit(), {0}); + assert.deepEqual(x.mod(y).to_8bit(), {0}); }); // it("Should calculate modulo of negative", []() { // auto x = Crunchy::zero().sub(Crunchy::from_8bit({4})), // y = Crunchy::from_8bit({3}); // - // Chai::assert.deepEqual(x.mod(y).to_8bit(), {2}); + // assert.deepEqual(x.mod(y).to_8bit(), {2}); // }); // // it("Should calculate modulo of negative", []() { // auto x = Crunchy::zero().sub(Crunchy::from_8bit({10, 18})), // y = Crunchy::from_8bit({123}); // - // Chai::assert.deepEqual(x.mod(y).to_8bit(), {5}); + // assert.deepEqual(x.mod(y).to_8bit(), {5}); // }); // // it("Should calculate modulo of negative", []() { // auto x = Crunchy::zero().sub(Crunchy::from_8bit({15, 62, 62, 18, 176})), // y = Crunchy::from_8bit({139, 207, 194, 82}); // - // Chai::assert.deepEqual(x.mod(y).to_8bit(), {12, 123, 46, 72}); + // assert.deepEqual(x.mod(y).to_8bit(), {12, 123, 46, 72}); // }); }); @@ -563,34 +564,34 @@ int main(int, char **) { auto x = Crunchy::from_8bit({22, 11}); size_t s = 5; - Chai::assert.deepEqual(x.shl(s).to_8bit(), {2, 193, 96}); + assert.deepEqual(x.shl(s).to_8bit(), {2, 193, 96}); }); it("Should left shift a number more", []() { auto x = Crunchy::from_8bit({1}); size_t s = 64; - Chai::assert.deepEqual(x.shl(s).to_8bit(), {1, 0, 0, 0, 0, 0, 0, 0, 0}); + assert.deepEqual(x.shl(s).to_8bit(), {1, 0, 0, 0, 0, 0, 0, 0, 0}); }); it("Should left shift zero", []() { auto x = Crunchy::from_8bit({0}); size_t s = 80; - Chai::assert.deepEqual(x.shl(s).to_8bit(), {0}); + assert.deepEqual(x.shl(s).to_8bit(), {0}); }); it("Should left shift negative", []() { auto x = Crunchy::from_8bit({3}); size_t s = 8; - Chai::assert.deepEqual(x.shl(s).to_8bit(), {3, 0}); + assert.deepEqual(x.shl(s).to_8bit(), {3, 0}); }); it("Should left shift one", []() { auto x = Crunchy::from_8bit({1, 0, 0, 0, 0}); size_t s = 1; - Chai::assert.deepEqual(x.shl(s).to_8bit(), {2, 0, 0, 0, 0}); + assert.deepEqual(x.shl(s).to_8bit(), {2, 0, 0, 0, 0}); }); }); @@ -599,29 +600,29 @@ int main(int, char **) { it("Should right shift a number to zero", []() { auto x = Crunchy::from_8bit({44, 44, 44}); - // Chai::assert.deepEqual(x.rsh(32).num, { 0 }); - Chai::assert.deepEqual(x.shr(32).to_8bit(), {0}); - Chai::assert.deepEqual(x.shr(33).to_8bit(), {0}); + // assert.deepEqual(x.rsh(32).num, { 0 }); + assert.deepEqual(x.shr(32).to_8bit(), {0}); + assert.deepEqual(x.shr(33).to_8bit(), {0}); }); it("Should right shift a number", []() { auto x = Crunchy::from_8bit({22, 11}); size_t s = 5; // std::cout << "XXXX 22:11" << x << std::endl; - Chai::assert.deepEqual(x.shr(s).to_8bit(), {176}); + assert.deepEqual(x.shr(s).to_8bit(), {176}); }); it("Should right shift a number out of existance", []() { auto x = Crunchy::from_8bit({22, 11}); size_t s = 20; - Chai::assert.deepEqual(x.shr(s).to_8bit(), {0}); + assert.deepEqual(x.shr(s).to_8bit(), {0}); }); it("Should right shift a negative number", []() { auto x = Crunchy::from_8bit({3}); size_t s = 8; - Chai::assert.deepEqual(x.shr(s).to_8bit(), {0}); + assert.deepEqual(x.shr(s).to_8bit(), {0}); }); }); diff --git a/cpp/test/test_ipaddress.cpp b/cpp/test/test_ipaddress.cpp index 248cb7e..64313f1 100644 --- a/cpp/test/test_ipaddress.cpp +++ b/cpp/test/test_ipaddress.cpp @@ -1,6 +1,7 @@ -#include "chai.hpp" -#include "mocha.hpp" + +#include +using namespace cascara; #include "../src/crunchy.hpp" #include "../src/ipaddress.hpp" @@ -29,7 +30,7 @@ RangeItem Range(size_t start, size_t target) { } void assertArrayEqual(std::vector a, std::vector b) { - Chai::assert.deepEqual(a, b); + assert.deepEqual(a, b); } IPAddressTest setup() { return IPAddressTest(); } @@ -40,44 +41,44 @@ int main() { it("test_method_ipaddress", []() { // std::cout << "-1" << std::endl; - Chai::assert.isTrue(IPAddress::parse(setup().valid_ipv4).isOk(), "valid_ipv4"); + assert.isTrue(IPAddress::parse(setup().valid_ipv4).isOk(), "valid_ipv4"); // std::cout << "-2" << std::endl; - Chai::assert.isTrue(IPAddress::parse(setup().valid_ipv6).isOk(), "valid_ipv6"); + assert.isTrue(IPAddress::parse(setup().valid_ipv6).isOk(), "valid_ipv6"); // std::cout << "-3" << std::endl; - Chai::assert.isTrue(IPAddress::parse(setup().valid_mapped).isOk(), "valid_mapped"); + assert.isTrue(IPAddress::parse(setup().valid_mapped).isOk(), "valid_mapped"); // std::cout << "-4" << std::endl; - Chai::assert.isTrue(IPAddress::parse(setup().valid_ipv4)->is_ipv4(), "isv4"); + assert.isTrue(IPAddress::parse(setup().valid_ipv4)->is_ipv4(), "isv4"); // std::cout << "-5" << std::endl; - Chai::assert.isTrue(IPAddress::parse(setup().valid_ipv6)->is_ipv6(), "isv6"); + assert.isTrue(IPAddress::parse(setup().valid_ipv6)->is_ipv6(), "isv6"); // std::cout << "-6" << std::endl; - Chai::assert.isTrue(IPAddress::parse(setup().valid_mapped)->is_mapped(), "ismapped"); + assert.isTrue(IPAddress::parse(setup().valid_mapped)->is_mapped(), "ismapped"); // std::cout << "-7" << std::endl; - Chai::assert.isTrue(IPAddress::parse(setup().invalid_ipv4).isErr(), "invalid_ipv4"); + assert.isTrue(IPAddress::parse(setup().invalid_ipv4).isErr(), "invalid_ipv4"); // std::cout << "-8" << std::endl; - Chai::assert.isTrue(IPAddress::parse(setup().invalid_ipv6).isErr(), "invalid_ipv6"); + assert.isTrue(IPAddress::parse(setup().invalid_ipv6).isErr(), "invalid_ipv6"); // std::cout << "-9" << std::endl; - Chai::assert.isTrue(IPAddress::parse(setup().invalid_mapped).isErr(), "invalid_mapped"); + assert.isTrue(IPAddress::parse(setup().invalid_mapped).isErr(), "invalid_mapped"); // std::cout << "-A" << std::endl; }); it("test_module_method_valid", []() { - Chai::assert.equal(true, IPAddress::is_valid("10.0.0.1")); - Chai::assert.equal(true, IPAddress::is_valid("10.0.0.0")); - Chai::assert.equal(true, IPAddress::is_valid("2002::1")); - Chai::assert.equal(true, IPAddress::is_valid("dead:beef:cafe:babe::f0ad")); - Chai::assert.equal(false, IPAddress::is_valid("10.0.0.256")); - Chai::assert.equal(false, IPAddress::is_valid("10.0.0.0.0")); - Chai::assert.equal(true, IPAddress::is_valid("10.0.0")); - Chai::assert.equal(true, IPAddress::is_valid("10.0")); - Chai::assert.equal(false, IPAddress::is_valid("2002:516:2:200")); - Chai::assert.equal(false, IPAddress::is_valid("2002:::1")); + assert.equal(true, IPAddress::is_valid("10.0.0.1")); + assert.equal(true, IPAddress::is_valid("10.0.0.0")); + assert.equal(true, IPAddress::is_valid("2002::1")); + assert.equal(true, IPAddress::is_valid("dead:beef:cafe:babe::f0ad")); + assert.equal(false, IPAddress::is_valid("10.0.0.256")); + assert.equal(false, IPAddress::is_valid("10.0.0.0.0")); + assert.equal(true, IPAddress::is_valid("10.0.0")); + assert.equal(true, IPAddress::is_valid("10.0")); + assert.equal(false, IPAddress::is_valid("2002:516:2:200")); + assert.equal(false, IPAddress::is_valid("2002:::1")); }); it("test_module_method_valid_ipv4_netmark", []() { - Chai::assert.equal(true, IPAddress::is_valid_netmask("255.255.255.0"), "255.255.255.0 should ok"); - Chai::assert.equal(false, IPAddress::is_valid_netmask("10.0.0.1"), "10.0.0.1 this is bad"); + assert.equal(true, IPAddress::is_valid_netmask("255.255.255.0"), "255.255.255.0 should ok"); + assert.equal(false, IPAddress::is_valid_netmask("10.0.0.1"), "10.0.0.1 this is bad"); }); it("test_summarize", []() { @@ -116,7 +117,7 @@ int main() { ip_addresses.push_back(IPAddress::parse(net).unwrap()); } - Chai::assert.equal(IPAddress::summarize_str({})->size(), 0); + assert.equal(IPAddress::summarize_str({})->size(), 0); assertArrayEqual( IPAddress::to_string_vec(IPAddress::summarize_str({"10.1.0.4/24"}).unwrap()), {"10.1.0.0/24"}); @@ -160,7 +161,7 @@ int main() { size_t cnt = 100; for (size_t _ = 0; _ < cnt; ++_) { - Chai::assert.deepEqual( + assert.deepEqual( IPAddress::to_string_vec(IPAddress::summarize(ip_addresses)), { "1.0.0.0/8", "2.0.0.0/7", "4.0.0.0/6", "8.0.0.0/7", "11.0.0.0/8", "12.0.0.0/6", @@ -189,8 +190,8 @@ int main() { assertArrayEqual(IPAddress::to_string_vec( IPAddress::summarize({ a1, a2 })), {"10.0.0.0/23"}); - Chai::assert.equal("10.0.0.1/24", a1.to_string()); - Chai::assert.equal("10.0.1.1/24", a2.to_string()); + assert.equal("10.0.0.1/24", a1.to_string()); + assert.equal("10.0.1.1/24", a2.to_string()); }); }); return exit(); diff --git a/cpp/test/test_ipv4.cpp b/cpp/test/test_ipv4.cpp index 6a71212..eba9694 100644 --- a/cpp/test/test_ipv4.cpp +++ b/cpp/test/test_ipv4.cpp @@ -1,6 +1,7 @@ -#include "chai.hpp" -#include "mocha.hpp" + +#include +using namespace cascara; #include "../src/ipaddress.hpp" @@ -91,23 +92,23 @@ int main() { for (auto i : setup().valid_ipv4) { //console.log(i[0]); auto ip = IPAddress::parse(i.first).unwrap(); - Chai::assert.isTrue(ip.is_ipv4() && !ip.is_ipv6()); + assert.isTrue(ip.is_ipv4() && !ip.is_ipv6()); } - Chai::assert.equal(32, setup().ip.prefix.ip_bits->bits); - Chai::assert.isTrue(IPAddress::parse("1.f.13.1/-3").isErr()); - Chai::assert.isTrue(IPAddress::parse("10.0.0.0/8").isOk()); + assert.equal(32, setup().ip.prefix.ip_bits->bits); + assert.isTrue(IPAddress::parse("1.f.13.1/-3").isErr()); + assert.isTrue(IPAddress::parse("10.0.0.0/8").isOk()); }); it("test_initialize_format_error", []() { for (auto i : setup().invalid_ipv4) { - Chai::assert.isTrue(IPAddress::parse(i).isErr()); + assert.isTrue(IPAddress::parse(i).isErr()); } - Chai::assert.isTrue(IPAddress::parse("10.0.0.0/asd").isErr()); + assert.isTrue(IPAddress::parse("10.0.0.0/asd").isErr()); }); it("test_initialize_without_prefix", []() { - Chai::assert.isTrue(IPAddress::parse("10.10.0.0").isOk()); + assert.isTrue(IPAddress::parse("10.10.0.0").isOk()); auto ip = IPAddress::parse("10.10.0.0").unwrap(); - Chai::assert.isTrue(!ip.is_ipv6() && ip.is_ipv4()); - Chai::assert.equal(32, ip.prefix.num); + assert.isTrue(!ip.is_ipv6() && ip.is_ipv4()); + assert.equal(32, ip.prefix.num); }); it("test_attributes", []() { for (auto i : setup().valid_ipv4) { @@ -115,13 +116,13 @@ int main() { auto attr = i.second; auto ip = IPAddress::parse(arg).unwrap(); // println!("test_attributes:{}:{:?}", arg, attr); - Chai::assert.equal(attr.ip, ip.to_s()); - Chai::assert.equal(attr.prefix, ip.prefix.num); + assert.equal(attr.ip, ip.to_s()); + assert.equal(attr.prefix, ip.prefix.num); } }); it("test_octets", []() { auto ip = IPAddress::parse("10.1.2.3/8").unwrap(); - Chai::assert.deepEqual(ip.parts(), {10, 1, 2, 3}); + assert.deepEqual(ip.parts(), {10, 1, 2, 3}); }); it("test_method_to_string", []() { for (auto i : setup().valid_ipv4) { @@ -130,7 +131,7 @@ int main() { auto ip = IPAddress::parse(arg).unwrap(); std::stringstream s2; s2 << attr.ip << "/" << attr.prefix; - Chai::assert.equal(s2.str(), ip.to_string()); + assert.equal(s2.str(), ip.to_string()); } }); it("test_method_to_s", []() { @@ -138,9 +139,9 @@ int main() { auto arg = i.first; auto attr = i.second; auto ip = IPAddress::parse(arg).unwrap(); - Chai::assert.equal(attr.ip, ip.to_s()); + assert.equal(attr.ip, ip.to_s()); // auto ip_c = IPAddress::parse(arg); - // Chai::assert.equal(attr.ip, ip.to_s()); + // assert.equal(attr.ip, ip.to_s()); } }); it("test_netmask", []() { @@ -148,7 +149,7 @@ int main() { auto addr = i.first; auto mask = i.second; auto ip = IPAddress::parse(addr).unwrap(); - Chai::assert.equal(ip.netmask().to_s(), mask); + assert.equal(ip.netmask().to_s(), mask); } }); it("test_method_to_u32", []() { @@ -156,23 +157,23 @@ int main() { auto addr = i.first; auto my = i.second; auto ip = IPAddress::parse(addr).unwrap(); - Chai::assert.isTrue(ip.host_address.eq(my)); + assert.isTrue(ip.host_address.eq(my)); } }); it("test_method_is_network", []() { - Chai::assert.equal(true, setup().network.is_network()); - Chai::assert.equal(false, setup().ip.is_network()); + assert.equal(true, setup().network.is_network()); + assert.equal(false, setup().ip.is_network()); }); it("test_one_address_network", []() { auto network = IPAddress::parse("172.16.10.1/32").unwrap(); - Chai::assert.equal(false, network.is_network()); + assert.equal(false, network.is_network()); }); it("test_method_broadcast", []() { for (auto i : setup().broadcast) { auto addr = i.first; auto bcast = i.second; auto ip = IPAddress::parse(addr).unwrap(); - Chai::assert.equal(bcast, ip.broadcast().to_string()); + assert.equal(bcast, ip.broadcast().to_string()); } } ); @@ -181,28 +182,28 @@ int main() { auto addr = i.first; auto net = i.second; auto ip = IPAddress::parse(addr).unwrap(); - Chai::assert.equal(net, ip.network().to_string()); + assert.equal(net, ip.network().to_string()); } } ); it("test_method_bits", []() { auto ip = IPAddress::parse("127.0.0.1").unwrap(); - Chai::assert.equal("01111111000000000000000000000001", ip.bits()); + assert.equal("01111111000000000000000000000001", ip.bits()); } ); it("test_method_first", []() { auto ip = IPAddress::parse("192.168.100.0/24").unwrap(); - Chai::assert.equal("192.168.100.1", ip.first().to_s()); + assert.equal("192.168.100.1", ip.first().to_s()); ip = IPAddress::parse("192.168.100.50/24").unwrap(); - Chai::assert.equal("192.168.100.1", ip.first().to_s()); + assert.equal("192.168.100.1", ip.first().to_s()); } ); it("test_method_last", []() { auto ip = IPAddress::parse("192.168.100.0/24").unwrap(); - Chai::assert.equal("192.168.100.254", ip.last().to_s()); + assert.equal("192.168.100.254", ip.last().to_s()); ip = IPAddress::parse("192.168.100.50/24").unwrap(); - Chai::assert.equal("192.168.100.254", ip.last().to_s()); + assert.equal("192.168.100.254", ip.last().to_s()); } ); it("test_method_each_host", []() { @@ -210,47 +211,47 @@ int main() { std::vector arr; ip.each_host([&arr](const IPAddress & i) { arr.push_back(i.to_s()); }); - Chai::assert.deepEqual(arr, {"10.0.0.1", "10.0.0.2", "10.0.0.3", "10.0.0.4", "10.0.0.5", "10.0.0.6"}); + assert.deepEqual(arr, {"10.0.0.1", "10.0.0.2", "10.0.0.3", "10.0.0.4", "10.0.0.5", "10.0.0.6"}); } ); it("test_method_each", []() { auto ip = IPAddress::parse("10.0.0.1/29").unwrap(); std::vector arr; ip.each([&arr](const IPAddress & i) { arr.push_back(i.to_s());}); - Chai::assert.deepEqual(arr, {"10.0.0.0", "10.0.0.1", "10.0.0.2", "10.0.0.3", "10.0.0.4", "10.0.0.5", + assert.deepEqual(arr, {"10.0.0.0", "10.0.0.1", "10.0.0.2", "10.0.0.3", "10.0.0.4", "10.0.0.5", "10.0.0.6", "10.0.0.7"}); } ); it("test_method_size", []() { auto ip = IPAddress::parse("10.0.0.1/29").unwrap(); - Chai::assert.isTrue(ip.size().eq(Crunchy::parse("8").unwrap())); + assert.isTrue(ip.size().eq(Crunchy::parse("8").unwrap())); } ); it("test_method_network_u32", []() { - Chai::assert.equal("2886732288", setup().ip.network().host_address.toString()); + assert.equal("2886732288", setup().ip.network().host_address.toString()); } ); it("test_method_broadcast_u32", []() { - Chai::assert.equal("2886732543", setup().ip.broadcast().host_address.toString()); + assert.equal("2886732543", setup().ip.broadcast().host_address.toString()); } ); it("test_method_include", []() { auto ip = IPAddress::parse("192.168.10.100/24").unwrap(); auto addr = IPAddress::parse("192.168.10.102/24").unwrap(); - Chai::assert.equal(true, ip.includes(addr)); - Chai::assert.equal(false, + assert.equal(true, ip.includes(addr)); + assert.equal(false, ip.includes(IPAddress::parse("172.16.0.48").unwrap())); ip = IPAddress::parse("10.0.0.0/8").unwrap(); - Chai::assert.equal(true, ip.includes(IPAddress::parse("10.0.0.0/9").unwrap())); - Chai::assert.equal(true, ip.includes(IPAddress::parse("10.1.1.1/32").unwrap())); - Chai::assert.equal(true, ip.includes(IPAddress::parse("10.1.1.1/9").unwrap())); - Chai::assert.equal(false, + assert.equal(true, ip.includes(IPAddress::parse("10.0.0.0/9").unwrap())); + assert.equal(true, ip.includes(IPAddress::parse("10.1.1.1/32").unwrap())); + assert.equal(true, ip.includes(IPAddress::parse("10.1.1.1/9").unwrap())); + assert.equal(false, ip.includes(IPAddress::parse("172.16.0.0/16").unwrap())); - Chai::assert.equal(false, ip.includes(IPAddress::parse("10.0.0.0/7").unwrap())); - Chai::assert.equal(false, ip.includes(IPAddress::parse("5.5.5.5/32").unwrap())); - Chai::assert.equal(false, ip.includes(IPAddress::parse("11.0.0.0/8").unwrap())); + assert.equal(false, ip.includes(IPAddress::parse("10.0.0.0/7").unwrap())); + assert.equal(false, ip.includes(IPAddress::parse("5.5.5.5/32").unwrap())); + assert.equal(false, ip.includes(IPAddress::parse("11.0.0.0/8").unwrap())); ip = IPAddress::parse("13.13.0.0/13").unwrap(); - Chai::assert.equal(false, + assert.equal(false, ip.includes(IPAddress::parse("13.16.0.0/32").unwrap())); } ); @@ -259,84 +260,84 @@ int main() { auto addr1 = IPAddress::parse("192.168.10.102/24").unwrap(); auto addr2 = IPAddress::parse("192.168.10.103/24").unwrap(); auto tmp = {addr1, addr2}; - Chai::assert.equal(true, ip.includes_all(tmp)); - Chai::assert.equal(false, + assert.equal(true, ip.includes_all(tmp)); + assert.equal(false, ip.includes_all({addr1, IPAddress::parse("13.16.0.0/32").unwrap()})); } ); it("test_method_ipv4", []() { - Chai::assert.equal(true, setup().ip.is_ipv4()); + assert.equal(true, setup().ip.is_ipv4()); } ); it("test_method_ipv6", []() { - Chai::assert.equal(false, setup().ip.is_ipv6()); + assert.equal(false, setup().ip.is_ipv6()); } ); it("test_method_private", []() { - Chai::assert.equal(true, + assert.equal(true, IPAddress::parse("192.168.10.50/24")->is_private()); - Chai::assert.equal(true, + assert.equal(true, IPAddress::parse("192.168.10.50/16")->is_private()); - Chai::assert.equal(true, + assert.equal(true, IPAddress::parse("172.16.77.40/24")->is_private()); - Chai::assert.equal(true, + assert.equal(true, IPAddress::parse("172.16.10.50/14")->is_private()); - Chai::assert.equal(true, + assert.equal(true, IPAddress::parse("10.10.10.10/10")->is_private()); - Chai::assert.equal(true, IPAddress::parse("10.0.0.0/8")->is_private()); - Chai::assert.equal(false, + assert.equal(true, IPAddress::parse("10.0.0.0/8")->is_private()); + assert.equal(false, IPAddress::parse("192.168.10.50/12")->is_private()); - Chai::assert.equal(false, IPAddress::parse("3.3.3.3")->is_private()); - Chai::assert.equal(false, IPAddress::parse("10.0.0.0/7")->is_private()); - Chai::assert.equal(false, + assert.equal(false, IPAddress::parse("3.3.3.3")->is_private()); + assert.equal(false, IPAddress::parse("10.0.0.0/7")->is_private()); + assert.equal(false, IPAddress::parse("172.32.0.0/12")->is_private()); - Chai::assert.equal(false, + assert.equal(false, IPAddress::parse("172.16.0.0/11")->is_private()); - Chai::assert.equal(false, + assert.equal(false, IPAddress::parse("192.0.0.2/24")->is_private()); } ); it("test_method_octet", []() { - Chai::assert.equal(setup().ip.parts()[0], 172); - Chai::assert.equal(setup().ip.parts()[1], 16); - Chai::assert.equal(setup().ip.parts()[2], 10); - Chai::assert.equal(setup().ip.parts()[3], 1); + assert.equal(setup().ip.parts()[0], 172); + assert.equal(setup().ip.parts()[1], 16); + assert.equal(setup().ip.parts()[2], 10); + assert.equal(setup().ip.parts()[3], 1); } ); it("test_method_a", []() { - Chai::assert.equal(true, Ipv4::is_class_a(setup().class_a)); - Chai::assert.equal(false, Ipv4::is_class_a(setup().class_b)); - Chai::assert.equal(false, Ipv4::is_class_a(setup().class_c)); + assert.equal(true, Ipv4::is_class_a(setup().class_a)); + assert.equal(false, Ipv4::is_class_a(setup().class_b)); + assert.equal(false, Ipv4::is_class_a(setup().class_c)); } ); it("test_method_b", []() { - Chai::assert.equal(true, Ipv4::is_class_b(setup().class_b)); - Chai::assert.equal(false, Ipv4::is_class_b(setup().class_a)); - Chai::assert.equal(false, Ipv4::is_class_b(setup().class_c)); + assert.equal(true, Ipv4::is_class_b(setup().class_b)); + assert.equal(false, Ipv4::is_class_b(setup().class_a)); + assert.equal(false, Ipv4::is_class_b(setup().class_c)); } ); it("test_method_c", []() { - Chai::assert.equal(true, Ipv4::is_class_c(setup().class_c)); - Chai::assert.equal(false, Ipv4::is_class_c(setup().class_a)); - Chai::assert.equal(false, Ipv4::is_class_c(setup().class_b)); + assert.equal(true, Ipv4::is_class_c(setup().class_c)); + assert.equal(false, Ipv4::is_class_c(setup().class_a)); + assert.equal(false, Ipv4::is_class_c(setup().class_b)); } ); it("test_method_to_ipv6", []() { - Chai::assert.equal("::ac10:a01", setup().ip.to_ipv6().to_s()); + assert.equal("::ac10:a01", setup().ip.to_ipv6().to_s()); } ); it("test_method_reverse", []() { - Chai::assert.equal(setup().ip.dns_reverse(), "10.16.172.in-addr.arpa"); + assert.equal(setup().ip.dns_reverse(), "10.16.172.in-addr.arpa"); } ); it("test_method_dns_rev_domains", []() { - Chai::assert.deepEqual(IPAddress::parse("173.17.5.1/23")->dns_rev_domains(), + assert.deepEqual(IPAddress::parse("173.17.5.1/23")->dns_rev_domains(), {"4.17.173.in-addr.arpa", "5.17.173.in-addr.arpa"}); - Chai::assert.deepEqual(IPAddress::parse("173.17.1.1/15")->dns_rev_domains(), + assert.deepEqual(IPAddress::parse("173.17.1.1/15")->dns_rev_domains(), {"16.173.in-addr.arpa", "17.173.in-addr.arpa"}); - Chai::assert.deepEqual(IPAddress::parse("173.17.1.1/7")->dns_rev_domains(), + assert.deepEqual(IPAddress::parse("173.17.1.1/7")->dns_rev_domains(), {"172.in-addr.arpa", "173.in-addr.arpa"}); - Chai::assert.deepEqual(IPAddress::parse("173.17.1.1/29")->dns_rev_domains(), + assert.deepEqual(IPAddress::parse("173.17.1.1/29")->dns_rev_domains(), { "0.1.17.173.in-addr.arpa", "1.1.17.173.in-addr.arpa", @@ -347,15 +348,15 @@ int main() { "6.1.17.173.in-addr.arpa", "7.1.17.173.in-addr.arpa" }); - Chai::assert.deepEqual(IPAddress::parse("174.17.1.1/24")->dns_rev_domains(), + assert.deepEqual(IPAddress::parse("174.17.1.1/24")->dns_rev_domains(), {"1.17.174.in-addr.arpa"}); - Chai::assert.deepEqual(IPAddress::parse("175.17.1.1/16")->dns_rev_domains(), + assert.deepEqual(IPAddress::parse("175.17.1.1/16")->dns_rev_domains(), {"17.175.in-addr.arpa"}); - Chai::assert.deepEqual(IPAddress::parse("176.17.1.1/8")->dns_rev_domains(), + assert.deepEqual(IPAddress::parse("176.17.1.1/8")->dns_rev_domains(), {"176.in-addr.arpa"}); - Chai::assert.deepEqual(IPAddress::parse("177.17.1.1/0")->dns_rev_domains(), + assert.deepEqual(IPAddress::parse("177.17.1.1/0")->dns_rev_domains(), {"in-addr.arpa"}); - Chai::assert.deepEqual(IPAddress::parse("178.17.1.1/32")->dns_rev_domains(), + assert.deepEqual(IPAddress::parse("178.17.1.1/32")->dns_rev_domains(), {"1.1.17.178.in-addr.arpa"}); } ); @@ -366,26 +367,26 @@ int main() { auto ip4 = IPAddress::parse("10.1.1.1/8").unwrap(); // ip2 should be greater than ip1 - Chai::assert.equal(true, ip1.lt(ip2)); - Chai::assert.equal(false, ip1.gt(ip2)); - Chai::assert.equal(false, ip2.lt(ip1)); + assert.equal(true, ip1.lt(ip2)); + assert.equal(false, ip1.gt(ip2)); + assert.equal(false, ip2.lt(ip1)); // ip2 should be less than ip3 - Chai::assert.equal(true, ip2.lt(ip3)); - Chai::assert.equal(false, ip2.gt(ip3)); + assert.equal(true, ip2.lt(ip3)); + assert.equal(false, ip2.gt(ip3)); // ip1 should be less than ip3 - Chai::assert.equal(true, ip1.lt(ip3)); - Chai::assert.equal(false, ip1.gt(ip3)); - Chai::assert.equal(false, ip3.lt(ip1)); + assert.equal(true, ip1.lt(ip3)); + assert.equal(false, ip1.gt(ip3)); + assert.equal(false, ip3.lt(ip1)); // ip1 should be equal to itself - Chai::assert.equal(true, ip1.eq(ip1)); + assert.equal(true, ip1.eq(ip1)); // ip1 should be equal to ip4 - Chai::assert.equal(true, ip1.eq(ip4)); + assert.equal(true, ip1.eq(ip4)); // test sorting std::vector res = { ip1, ip2, ip3 } ; std::sort (res.begin(), res.end(), [](const IPAddress &a, const IPAddress &b) { return a.lt(b); }); - Chai::assert.deepEqual(IPAddress::to_string_vec(res), {"10.1.1.1/8", "10.1.1.1/16", "172.16.1.1/14"}); + assert.deepEqual(IPAddress::to_string_vec(res), {"10.1.1.1/8", "10.1.1.1/16", "172.16.1.1/14"}); // test same prefix ip1 = IPAddress::parse("10.0.0.0/24").unwrap(); ip2 = IPAddress::parse("10.0.0.0/16").unwrap(); @@ -395,61 +396,61 @@ int main() { std::sort (res.begin(), res.end(), [](const IPAddress &a, const IPAddress &b) { return a.lt(b); }); - Chai::assert.deepEqual(IPAddress::to_string_vec(res), {"10.0.0.0/8", "10.0.0.0/16", "10.0.0.0/24"}); + assert.deepEqual(IPAddress::to_string_vec(res), {"10.0.0.0/8", "10.0.0.0/16", "10.0.0.0/24"}); } } ); it("test_method_minus", []() { auto ip1 = IPAddress::parse("10.1.1.1/8").unwrap(); auto ip2 = IPAddress::parse("10.1.1.10/8").unwrap(); - Chai::assert.equal("9", ip2.sub(ip1).toString()); - Chai::assert.equal("9", ip1.sub(ip2).toString()); + assert.equal("9", ip2.sub(ip1).toString()); + assert.equal("9", ip1.sub(ip2).toString()); } ); it("test_method_plus", []() { auto ip1 = IPAddress::parse("172.16.10.1/24").unwrap(); auto ip2 = IPAddress::parse("172.16.11.2/24").unwrap(); - Chai::assert.deepEqual(IPAddress::to_string_vec(ip1.add(ip2)), {"172.16.10.0/23"}); + assert.deepEqual(IPAddress::to_string_vec(ip1.add(ip2)), {"172.16.10.0/23"}); ip2 = IPAddress::parse("172.16.12.2/24").unwrap(); - Chai::assert.deepEqual(IPAddress::to_string_vec(ip1.add(ip2)), + assert.deepEqual(IPAddress::to_string_vec(ip1.add(ip2)), {ip1.network().to_string(), ip2.network().to_string()}); ip1 = IPAddress::parse("10.0.0.0/23").unwrap(); ip2 = IPAddress::parse("10.0.2.0/24").unwrap(); - Chai::assert.deepEqual(IPAddress::to_string_vec(ip1.add(ip2)), + assert.deepEqual(IPAddress::to_string_vec(ip1.add(ip2)), {"10.0.0.0/23", "10.0.2.0/24"}); ip1 = IPAddress::parse("10.0.0.0/23").unwrap(); ip2 = IPAddress::parse("10.0.2.0/24").unwrap(); - Chai::assert.deepEqual(IPAddress::to_string_vec(ip1.add(ip2)), + assert.deepEqual(IPAddress::to_string_vec(ip1.add(ip2)), {"10.0.0.0/23", "10.0.2.0/24"}); ip1 = IPAddress::parse("10.0.0.0/16").unwrap(); ip2 = IPAddress::parse("10.0.2.0/24").unwrap(); - Chai::assert.deepEqual(IPAddress::to_string_vec(ip1.add(ip2)), {"10.0.0.0/16"}); + assert.deepEqual(IPAddress::to_string_vec(ip1.add(ip2)), {"10.0.0.0/16"}); ip1 = IPAddress::parse("10.0.0.0/23").unwrap(); ip2 = IPAddress::parse("10.1.0.0/24").unwrap(); - Chai::assert.deepEqual(IPAddress::to_string_vec(ip1.add(ip2)), + assert.deepEqual(IPAddress::to_string_vec(ip1.add(ip2)), {"10.0.0.0/23", "10.1.0.0/24"}); } ); it("test_method_netmask_equal", []() { auto ip = IPAddress::parse("10.1.1.1/16").unwrap(); - Chai::assert.equal(16, ip.prefix.get_prefix()); + assert.equal(16u, ip.prefix.get_prefix()); auto ip2 = ip.change_netmask("255.255.255.0").unwrap(); - Chai::assert.equal(24, ip2.prefix.get_prefix()); + assert.equal(24u, ip2.prefix.get_prefix()); } ); it("test_method_split", []() { - Chai::assert.isTrue(setup().ip.split(0).isErr()); - Chai::assert.isTrue(setup().ip.split(257).isErr()); + assert.isTrue(setup().ip.split(0).isErr()); + assert.isTrue(setup().ip.split(257).isErr()); - Chai::assert.deepEqual(IPAddress::to_string_vec(setup().ip.split(1).unwrap()), + assert.deepEqual(IPAddress::to_string_vec(setup().ip.split(1).unwrap()), {setup().ip.network().to_string()}); - Chai::assert.deepEqual(IPAddress::to_string_vec(setup().network.split(8).unwrap()), + assert.deepEqual(IPAddress::to_string_vec(setup().network.split(8).unwrap()), {"172.16.10.0/27", "172.16.10.32/27", "172.16.10.64/27", @@ -459,7 +460,7 @@ int main() { "172.16.10.192/27", "172.16.10.224/27"}); - Chai::assert.deepEqual(IPAddress::to_string_vec(setup().network.split(7).unwrap()), + assert.deepEqual(IPAddress::to_string_vec(setup().network.split(7).unwrap()), {"172.16.10.0/27", "172.16.10.32/27", "172.16.10.64/27", @@ -468,51 +469,51 @@ int main() { "172.16.10.160/27", "172.16.10.192/26"}); - Chai::assert.deepEqual(IPAddress::to_string_vec(setup().network.split(6).unwrap()), + assert.deepEqual(IPAddress::to_string_vec(setup().network.split(6).unwrap()), {"172.16.10.0/27", "172.16.10.32/27", "172.16.10.64/27", "172.16.10.96/27", "172.16.10.128/26", "172.16.10.192/26"}); - Chai::assert.deepEqual(IPAddress::to_string_vec(setup().network.split(5).unwrap()), + assert.deepEqual(IPAddress::to_string_vec(setup().network.split(5).unwrap()), {"172.16.10.0/27", "172.16.10.32/27", "172.16.10.64/27", "172.16.10.96/27", "172.16.10.128/25"}); - Chai::assert.deepEqual(IPAddress::to_string_vec(setup().network.split(4).unwrap()), + assert.deepEqual(IPAddress::to_string_vec(setup().network.split(4).unwrap()), {"172.16.10.0/26", "172.16.10.64/26", "172.16.10.128/26", "172.16.10.192/26"}); - Chai::assert.deepEqual(IPAddress::to_string_vec(setup().network.split(3).unwrap()), + assert.deepEqual(IPAddress::to_string_vec(setup().network.split(3).unwrap()), {"172.16.10.0/26", "172.16.10.64/26", "172.16.10.128/25"}); - Chai::assert.deepEqual(IPAddress::to_string_vec(setup().network.split(2).unwrap()), + assert.deepEqual(IPAddress::to_string_vec(setup().network.split(2).unwrap()), {"172.16.10.0/25", "172.16.10.128/25"}); - Chai::assert.deepEqual(IPAddress::to_string_vec(setup().network.split(1).unwrap()), + assert.deepEqual(IPAddress::to_string_vec(setup().network.split(1).unwrap()), {"172.16.10.0/24"}); } ); it("test_method_subnet", []() { - Chai::assert.isTrue(setup().network.subnet(23).isErr()); - Chai::assert.isTrue(setup().network.subnet(33).isErr()); - Chai::assert.isTrue(setup().ip.subnet(30).isOk()); - Chai::assert.deepEqual(IPAddress::to_string_vec(setup().network.subnet(26).unwrap()), + assert.isTrue(setup().network.subnet(23).isErr()); + assert.isTrue(setup().network.subnet(33).isErr()); + assert.isTrue(setup().ip.subnet(30).isOk()); + assert.deepEqual(IPAddress::to_string_vec(setup().network.subnet(26).unwrap()), {"172.16.10.0/26", "172.16.10.64/26", "172.16.10.128/26", "172.16.10.192/26"}); - Chai::assert.deepEqual(IPAddress::to_string_vec(setup().network.subnet(25).unwrap()), + assert.deepEqual(IPAddress::to_string_vec(setup().network.subnet(25).unwrap()), {"172.16.10.0/25", "172.16.10.128/25"}); - Chai::assert.deepEqual(IPAddress::to_string_vec(setup().network.subnet(24).unwrap()), + assert.deepEqual(IPAddress::to_string_vec(setup().network.subnet(24).unwrap()), {"172.16.10.0/24"}); } ); it("test_method_supernet", []() { - Chai::assert.isTrue(setup().ip.supernet(24).isErr()); - Chai::assert.equal("0.0.0.0/0", setup().ip.supernet(0)->to_string()); - // Chai::assert.equal("0.0.0.0/0", setup().ip.supernet(-2).to_string()); - Chai::assert.equal("172.16.10.0/23", + assert.isTrue(setup().ip.supernet(24).isErr()); + assert.equal("0.0.0.0/0", setup().ip.supernet(0)->to_string()); + // assert.equal("0.0.0.0/0", setup().ip.supernet(-2).to_string()); + assert.equal("172.16.10.0/23", setup().ip.supernet(23)->to_string()); - Chai::assert.equal("172.16.8.0/22", + assert.equal("172.16.8.0/22", setup().ip.supernet(22)->to_string()); } ); @@ -524,18 +525,18 @@ int main() { auto splitted = IPAddress::split_at_slash(addr); auto num = IPAddress::parse_dec_str(splitted->netmask.unwrap()).unwrap(); auto ip2 = ip.change_prefix(num).unwrap(); - Chai::assert.equal(ip2.to_string(), addr); + assert.equal(ip2.to_string(), addr); } }); it("test_classmethod_summarize", []() { // Should return self if only one network given - Chai::assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({setup().ip})), + assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({setup().ip})), {setup().ip.network().to_string()}); // Summarize homogeneous networks auto ip1 = IPAddress::parse("172.16.10.1/24").unwrap(); auto ip2 = IPAddress::parse("172.16.11.2/24").unwrap(); - Chai::assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({ip1, ip2})), + assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({ip1, ip2})), {"172.16.10.0/23"}); { @@ -543,7 +544,7 @@ int main() { auto ip2 = IPAddress::parse("10.0.1.1/24").unwrap(); auto ip3 = IPAddress::parse("10.0.2.1/24").unwrap(); auto ip4 = IPAddress::parse("10.0.3.1/24").unwrap(); - Chai::assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({ip1, ip2, ip3, ip4})), + assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({ip1, ip2, ip3, ip4})), {"10.0.0.0/22"}); } { @@ -551,38 +552,38 @@ int main() { auto ip2 = IPAddress::parse("10.0.1.1/24").unwrap(); auto ip3 = IPAddress::parse("10.0.2.1/24").unwrap(); auto ip4 = IPAddress::parse("10.0.3.1/24").unwrap(); - Chai::assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({ip4, ip3, ip2, ip1})), + assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({ip4, ip3, ip2, ip1})), {"10.0.0.0/22"}); } // Summarize non homogeneous networks ip1 = IPAddress::parse("10.0.0.0/23").unwrap(); ip2 = IPAddress::parse("10.0.2.0/24").unwrap(); - Chai::assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({ip1, ip2})), + assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({ip1, ip2})), {"10.0.0.0/23", "10.0.2.0/24"}); ip1 = IPAddress::parse("10.0.0.0/16").unwrap(); ip2 = IPAddress::parse("10.0.2.0/24").unwrap(); - Chai::assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({ip1, ip2})), + assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({ip1, ip2})), {"10.0.0.0/16"}); ip1 = IPAddress::parse("10.0.0.0/23").unwrap(); ip2 = IPAddress::parse("10.1.0.0/24").unwrap(); - Chai::assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({ip1, ip2})), + assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({ip1, ip2})), {"10.0.0.0/23", "10.1.0.0/24"}); ip1 = IPAddress::parse("10.0.0.0/23").unwrap(); ip2 = IPAddress::parse("10.0.2.0/23").unwrap(); auto ip3 = IPAddress::parse("10.0.4.0/24").unwrap(); auto ip4 = IPAddress::parse("10.0.6.0/24").unwrap(); - Chai::assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({ip1, ip2, ip3, ip4})), + assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({ip1, ip2, ip3, ip4})), {"10.0.0.0/22", "10.0.4.0/24", "10.0.6.0/24"}); { auto ip1 = IPAddress::parse("10.0.1.1/24").unwrap(); auto ip2 = IPAddress::parse("10.0.2.1/24").unwrap(); auto ip3 = IPAddress::parse("10.0.3.1/24").unwrap(); auto ip4 = IPAddress::parse("10.0.4.1/24").unwrap(); - Chai::assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({ip1, ip2, ip3, ip4})), + assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({ip1, ip2, ip3, ip4})), {"10.0.1.0/24", "10.0.2.0/23", "10.0.4.0/24"}); } { @@ -590,7 +591,7 @@ int main() { auto ip2 = IPAddress::parse("10.0.2.1/24").unwrap(); auto ip3 = IPAddress::parse("10.0.3.1/24").unwrap(); auto ip4 = IPAddress::parse("10.0.4.1/24").unwrap(); - Chai::assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({ip4, ip3, ip2, ip1})), + assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({ip4, ip3, ip2, ip1})), {"10.0.1.0/24", "10.0.2.0/23", "10.0.4.0/24"}); } @@ -598,22 +599,22 @@ int main() { ip2 = IPAddress::parse("10.10.2.1/24").unwrap(); ip3 = IPAddress::parse("172.16.0.1/24").unwrap(); ip4 = IPAddress::parse("172.16.1.1/24").unwrap(); - Chai::assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({ip1, ip2, ip3, ip4})), + assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize({ip1, ip2, ip3, ip4})), {"10.0.1.0/24", "10.10.2.0/24", "172.16.0.0/23"}); auto ips = {IPAddress::parse("10.0.0.12/30").unwrap(), IPAddress::parse("10.0.100.0/24").unwrap()}; - Chai::assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize(ips)), + assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize(ips)), {"10.0.0.12/30", "10.0.100.0/24"}); ips = {IPAddress::parse("172.16.0.0/31").unwrap(), IPAddress::parse("10.10.2.1/32").unwrap()}; - Chai::assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize(ips)), + assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize(ips)), {"10.10.2.1/32", "172.16.0.0/31"}); ips = {IPAddress::parse("172.16.0.0/32").unwrap(), IPAddress::parse("10.10.2.1/32").unwrap()}; - Chai::assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize(ips)), + assert.deepEqual(IPAddress::to_string_vec(IPAddress::summarize(ips)), {"10.10.2.1/32", "172.16.0.0/32"}); }); @@ -622,12 +623,12 @@ int main() { auto ip = i.first; auto prefix = i.second; auto res = Ipv4::parse_classful(ip).unwrap(); - Chai::assert.equal(prefix, res.prefix.num); + assert.equal(prefix, res.prefix.num); std::stringstream s2; s2 << ip << "/" << prefix; - Chai::assert.equal(s2.str(), res.to_string()); + assert.equal(s2.str(), res.to_string()); } - Chai::assert.isTrue(Ipv4::parse_classful("192.168.256.257").isErr()); + assert.isTrue(Ipv4::parse_classful("192.168.256.257").isErr()); }); }); return exit(); diff --git a/cpp/test/test_ipv6.cpp b/cpp/test/test_ipv6.cpp index ba55672..0faeeec 100644 --- a/cpp/test/test_ipv6.cpp +++ b/cpp/test/test_ipv6.cpp @@ -1,6 +1,7 @@ -#include "chai.hpp" -#include "mocha.hpp" + +#include +using namespace cascara; #include "../src/crunchy.hpp" #include "../src/ipaddress.hpp" @@ -81,26 +82,26 @@ int main() { it("test_attribute_address", []() { auto addr = "2001:0db8:0000:0000:0008:0800:200c:417a"; - Chai::assert.equal(addr, setup().ip.to_s_uncompressed()); + assert.equal(addr, setup().ip.to_s_uncompressed()); }); it("test_initialize", []() { - Chai::assert.equal(false, setup().ip.is_ipv4(), "is_ipv4"); + assert.equal(false, setup().ip.is_ipv4(), "is_ipv4"); for (auto ip : setup().valid_ipv6) { - Chai::assert.isTrue(IPAddress::parse(ip.first).isOk(), ip.first); + assert.isTrue(IPAddress::parse(ip.first).isOk(), ip.first); } for (auto ip : setup().invalid_ipv6) { - Chai::assert.isTrue(IPAddress::parse(ip).isErr(), ip); + assert.isTrue(IPAddress::parse(ip).isErr(), ip); } - Chai::assert.equal(64, setup().ip.prefix.num, "prefix"); + assert.equal(64, setup().ip.prefix.num, "prefix"); - Chai::assert.isTrue(IPAddress::parse("::10.1.1.1").isOk(), "mapped"); + assert.isTrue(IPAddress::parse("::10.1.1.1").isOk(), "mapped"); }); it("test_attribute_groups", []() { - Chai::assert.deepEqual(setup().arr, setup().ip.parts()); + assert.deepEqual(setup().arr, setup().ip.parts()); }); it("test_method_hexs", []() { - Chai::assert.deepEqual(setup().ip.parts_hex_str(), + assert.deepEqual(setup().ip.parts_hex_str(), {"2001", "0db8", "0000", "0000", "0008", "0800", "200c", "417a"}); }); @@ -108,103 +109,103 @@ int main() { for (auto i : setup().valid_ipv6) { auto ip = i.first; auto num = i.second; - Chai::assert.isTrue(num.eq(IPAddress::parse(ip)->host_address)); + assert.isTrue(num.eq(IPAddress::parse(ip)->host_address)); } }); it("test_method_set_prefix", []() { auto ip = IPAddress::parse("2001:db8::8:800:200c:417a").unwrap(); - Chai::assert.equal(128, ip.prefix.num); - Chai::assert.equal("2001:db8::8:800:200c:417a/128", ip.to_string()); + assert.equal(128, ip.prefix.num); + assert.equal("2001:db8::8:800:200c:417a/128", ip.to_string()); auto nip = ip.change_prefix(64).unwrap(); - Chai::assert.equal(64, nip.prefix.num); - Chai::assert.equal("2001:db8::8:800:200c:417a/64", nip.to_string()); + assert.equal(64, nip.prefix.num); + assert.equal("2001:db8::8:800:200c:417a/64", nip.to_string()); }); it("test_method_mapped", []() { - Chai::assert.equal(false, setup().ip.is_mapped()); + assert.equal(false, setup().ip.is_mapped()); auto ip6 = IPAddress::parse("::ffff:1234:5678").unwrap(); - Chai::assert.equal(true, ip6.is_mapped()); + assert.equal(true, ip6.is_mapped()); }); it("test_method_group", []() { auto s = setup(); - Chai::assert.deepEqual(s.ip.parts(), s.arr); + assert.deepEqual(s.ip.parts(), s.arr); }); it("test_method_ipv4()", - []() { Chai::assert.equal(false, setup().ip.is_ipv4()); }); + []() { assert.equal(false, setup().ip.is_ipv4()); }); it("test_method_ipv6", - []() { Chai::assert.equal(true, setup().ip.is_ipv6()); }); + []() { assert.equal(true, setup().ip.is_ipv6()); }); it("test_method_network_known", []() { - Chai::assert.equal(true, setup().network.is_network()); - Chai::assert.equal(false, setup().ip.is_network()); + assert.equal(true, setup().network.is_network()); + assert.equal(false, setup().ip.is_network()); }); it("test_method_network_u128", []() { - Chai::assert.isTrue( + assert.isTrue( Ipv6::from_int(Crunchy::parse("42540766411282592856903984951653826560").unwrap(), 64).unwrap() .eq(setup().ip.network())); }); it("test_method_broadcast_u128", []() { - Chai::assert.isTrue( + assert.isTrue( Ipv6::from_int(Crunchy::parse("42540766411282592875350729025363378175").unwrap(), 64).unwrap() .eq(setup().ip.broadcast())); }); it("test_method_size", []() { auto ip = IPAddress::parse("2001:db8::8:800:200c:417a/64").unwrap(); - Chai::assert.isTrue(Crunchy::one().shl(64).eq(ip.size())); + assert.isTrue(Crunchy::one().shl(64).eq(ip.size())); ip = IPAddress::parse("2001:db8::8:800:200c:417a/32").unwrap(); - Chai::assert.isTrue(Crunchy::one().shl(96).eq(ip.size())); + assert.isTrue(Crunchy::one().shl(96).eq(ip.size())); ip = IPAddress::parse("2001:db8::8:800:200c:417a/120").unwrap(); - Chai::assert.isTrue(Crunchy::one().shl(8).eq(ip.size())); + assert.isTrue(Crunchy::one().shl(8).eq(ip.size())); ip = IPAddress::parse("2001:db8::8:800:200c:417a/124").unwrap(); - Chai::assert.isTrue(Crunchy::one().shl(4).eq(ip.size())); + assert.isTrue(Crunchy::one().shl(4).eq(ip.size())); }); it("test_method_includes", []() { auto ip = setup().ip; - Chai::assert.equal(true, ip.includes(ip)); + assert.equal(true, ip.includes(ip)); // test prefix on same address auto included = IPAddress::parse("2001:db8::8:800:200c:417a/128").unwrap(); auto not_included = IPAddress::parse("2001:db8::8:800:200c:417a/46").unwrap(); - Chai::assert.equal(true, ip.includes(included)); - Chai::assert.equal(false, ip.includes(not_included)); + assert.equal(true, ip.includes(included)); + assert.equal(false, ip.includes(not_included)); // test address on same prefix included = IPAddress::parse("2001:db8::8:800:200c:0/64").unwrap(); not_included = IPAddress::parse("2001:db8:1::8:800:200c:417a/64").unwrap(); - Chai::assert.equal(true, ip.includes(included)); - Chai::assert.equal(false, ip.includes(not_included)); + assert.equal(true, ip.includes(included)); + assert.equal(false, ip.includes(not_included)); // general test included = IPAddress::parse("2001:db8::8:800:200c:1/128").unwrap(); not_included = IPAddress::parse("2001:db8:1::8:800:200c:417a/76").unwrap(); - Chai::assert.equal(true, ip.includes(included)); - Chai::assert.equal(false, ip.includes(not_included)); + assert.equal(true, ip.includes(included)); + assert.equal(false, ip.includes(not_included)); }); it("test_method_to_hex", - []() { Chai::assert.equal(setup().hex, setup().ip.to_hex()); }); + []() { assert.equal(setup().hex, setup().ip.to_hex()); }); it("test_method_to_s", []() { - Chai::assert.equal("2001:db8::8:800:200c:417a", setup().ip.to_s()); + assert.equal("2001:db8::8:800:200c:417a", setup().ip.to_s()); }); it("test_method_to_string", []() { - Chai::assert.equal("2001:db8::8:800:200c:417a/64", setup().ip.to_string()); + assert.equal("2001:db8::8:800:200c:417a/64", setup().ip.to_string()); }); it("test_method_to_string_uncompressed", []() { auto str = "2001:0db8:0000:0000:0008:0800:200c:417a/64"; - Chai::assert.equal(str, setup().ip.to_string_uncompressed()); + assert.equal(str, setup().ip.to_string_uncompressed()); }); it("test_method_reverse", []() { auto str = "f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.0.5.0.5.0.e.f.f." "3.ip6.arpa"; - Chai::assert.equal(str, IPAddress::parse("3ffe:505:2::f")->dns_reverse()); + assert.equal(str, IPAddress::parse("3ffe:505:2::f")->dns_reverse()); }); it("test_method_dns_rev_domains", []() { - Chai::assert.deepEqual(IPAddress::parse("f000:f100::/3")->dns_rev_domains(), + assert.deepEqual(IPAddress::parse("f000:f100::/3")->dns_rev_domains(), {"e.ip6.arpa", "f.ip6.arpa"}); - Chai::assert.deepEqual(IPAddress::parse("fea3:f120::/15")->dns_rev_domains(), + assert.deepEqual(IPAddress::parse("fea3:f120::/15")->dns_rev_domains(), {"2.a.e.f.ip6.arpa", "3.a.e.f.ip6.arpa" }); - Chai::assert.deepEqual(IPAddress::parse("3a03:2f80:f::/48")->dns_rev_domains(), + assert.deepEqual(IPAddress::parse("3a03:2f80:f::/48")->dns_rev_domains(), {"f.0.0.0.0.8.f.2.3.0.a.3.ip6.arpa" }); - Chai::assert.deepEqual(IPAddress::parse("f000:f100::1234/125")->dns_rev_domains(), + assert.deepEqual(IPAddress::parse("f000:f100::1234/125")->dns_rev_domains(), {"0.3.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.f.0.0.0.f.ip6.arpa", "1.3.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.f.0.0.0.f.ip6.arpa", "2.3.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.f.0.0.0.f.ip6.arpa", @@ -217,43 +218,43 @@ int main() { } ); it("test_method_compressed", []() { - Chai::assert.equal("1:1:1::1", + assert.equal("1:1:1::1", IPAddress::parse("1:1:1:0:0:0:0:1")->to_s()); - Chai::assert.equal("1:0:1::1", + assert.equal("1:0:1::1", IPAddress::parse("1:0:1:0:0:0:0:1")->to_s()); - Chai::assert.equal("1::1:1:1:2:3:1", + assert.equal("1::1:1:1:2:3:1", IPAddress::parse("1:0:1:1:1:2:3:1")->to_s()); - Chai::assert.equal("1::1:1:0:2:3:1", + assert.equal("1::1:1:0:2:3:1", IPAddress::parse("1:0:1:1::2:3:1")->to_s()); - Chai::assert.equal("1:0:0:1::1", + assert.equal("1:0:0:1::1", IPAddress::parse("1:0:0:1:0:0:0:1")->to_s()); - Chai::assert.equal("1::1:0:0:1", + assert.equal("1::1:0:0:1", IPAddress::parse("1:0:0:0:1:0:0:1")->to_s()); - Chai::assert.equal("1::1", IPAddress::parse("1:0:0:0:0:0:0:1")->to_s()); - // Chai::assert.equal("1:1.1:2:0:0:1", + assert.equal("1::1", IPAddress::parse("1:0:0:0:0:0:0:1")->to_s()); + // assert.equal("1:1.1:2:0:0:1", // IPAddress::parse("1:1:0:1:2.1").to_s }); it("test_method_unspecified", []() { - Chai::assert.equal(true, IPAddress::parse("::")->is_unspecified()); - Chai::assert.equal(false, setup().ip.is_unspecified()); + assert.equal(true, IPAddress::parse("::")->is_unspecified()); + assert.equal(false, setup().ip.is_unspecified()); }); it("test_method_loopback", []() { - Chai::assert.equal(true, IPAddress::parse("::1")->is_loopback()); - Chai::assert.equal(false, setup().ip.is_loopback()); + assert.equal(true, IPAddress::parse("::1")->is_loopback()); + assert.equal(false, setup().ip.is_loopback()); }); it("test_method_network", []() { for (auto i : setup().networks) { auto addr = i.first; auto net = i.second; auto ip = IPAddress::parse(addr).unwrap(); - Chai::assert.equal(net, ip.network().to_string()); + assert.equal(net, ip.network().to_string()); } }); it("test_method_each", []() { auto ip = IPAddress::parse("2001:db8::4/125").unwrap(); std::vector arr; ip.each([&arr](const IPAddress &i) { arr.push_back(i.to_s()); }); - Chai::assert.deepEqual(arr, {"2001:db8::", "2001:db8::1", "2001:db8::2", "2001:db8::3", + assert.deepEqual(arr, {"2001:db8::", "2001:db8::1", "2001:db8::2", "2001:db8::3", "2001:db8::4", "2001:db8::5", "2001:db8::6", "2001:db8::7" }); } @@ -284,10 +285,10 @@ int main() { s2 << adr << "/" << prefix; auto net_adr = IPAddress::parse(s2.str()).unwrap(); auto ret = net_adr.dns_networks(); - Chai::assert.equal(ret[0].prefix.num % 4, 0); - Chai::assert.equal(ret.size(), nr_networks); - Chai::assert.equal(net_adr.network().to_s(), ret[0].network().to_s()); - Chai::assert.equal(net_adr.broadcast().to_s(), + assert.equal(ret[0].prefix.num % 4, 0); + assert.equal(ret.size(), nr_networks); + assert.equal(net_adr.network().to_s(), ret[0].network().to_s()); + assert.equal(net_adr.broadcast().to_s(), ret[ret.size() - 1].broadcast().to_s()); // puts "//{adr}///{prefix} //{nr_networks} //{ret}" } @@ -296,12 +297,12 @@ int main() { for (auto i : IPAddress::parse("fd01:db8::4/3")->dns_networks()) { ret0.push_back(i.to_string()); } - Chai::assert.deepEqual(ret0, {"e000::/4", "f000::/4" }); + assert.deepEqual(ret0, {"e000::/4", "f000::/4" }); std::vector ret1; for (auto i : IPAddress::parse("3a03:2f80:f::/48")->dns_networks()) { ret1.push_back(i.to_string()); } - Chai::assert.deepEqual(ret1, {"3a03:2f80:f::/48" }); + assert.deepEqual(ret1, {"3a03:2f80:f::/48" }); }); it("test_method_compare", []() { auto ip1 = IPAddress::parse("2001:db8:1::1/64").unwrap(); @@ -310,48 +311,48 @@ int main() { auto ip4 = IPAddress::parse("2001:db8:1::1/65").unwrap(); // ip2 should be greater than ip1 - Chai::assert.equal(true, ip2.gt(ip1)); - Chai::assert.equal(false, ip1.gt(ip2)); - Chai::assert.equal(false, ip2.lt(ip1)); + assert.equal(true, ip2.gt(ip1)); + assert.equal(false, ip1.gt(ip2)); + assert.equal(false, ip2.lt(ip1)); // ip3 should be less than ip2 - Chai::assert.equal(true, ip2.gt(ip3)); - Chai::assert.equal(false, ip2.lt(ip3)); + assert.equal(true, ip2.gt(ip3)); + assert.equal(false, ip2.lt(ip3)); // ip1 should be less than ip3 - Chai::assert.equal(true, ip1.lt(ip3)); - Chai::assert.equal(false, ip1.gt(ip3)); - Chai::assert.equal(false, ip3.lt(ip1)); + assert.equal(true, ip1.lt(ip3)); + assert.equal(false, ip1.gt(ip3)); + assert.equal(false, ip3.lt(ip1)); // ip1 should be equal to itself - Chai::assert.equal(true, ip1.eq(ip1)); + assert.equal(true, ip1.eq(ip1)); // ip4 should be greater than ip1 - Chai::assert.equal(true, ip1.lt(ip4)); - Chai::assert.equal(false, ip1.gt(ip4)); + assert.equal(true, ip1.lt(ip4)); + assert.equal(false, ip1.gt(ip4)); // test sorting std::vector res = { ip1, ip2, ip3, ip4 } ; std::sort (res.begin(), res.end(), [](const IPAddress &a, const IPAddress &b) { return a.lt(b); }); - Chai::assert.deepEqual(IPAddress::to_string_vec(res), + assert.deepEqual(IPAddress::to_string_vec(res), {"2001:db8:1::1/64", "2001:db8:1::1/65", "2001:db8:1::2/64", "2001:db8:2::1/64"}); } // it("test_classmethod_expand", []() { // auto compressed = "2001:db8:0:cd30."; // auto expanded = "2001:0db8:0000:cd30:0000:0000:0000:0000"; - // Chai::assert.equal(expanded, @klass.expand(compressed)); - // Chai::assert.equal(expanded, @klass.expand("2001:0db8:0.cd3")); - // Chai::assert.equal(expanded, @klass.expand("2001:0db8.cd30")); - // Chai::assert.equal(expanded, @klass.expand("2001:0db8.cd3")); + // assert.equal(expanded, @klass.expand(compressed)); + // assert.equal(expanded, @klass.expand("2001:0db8:0.cd3")); + // assert.equal(expanded, @klass.expand("2001:0db8.cd30")); + // assert.equal(expanded, @klass.expand("2001:0db8.cd3")); // } ); it("test_classmethod_compress", []() { auto compressed = "2001:db8:0:cd30::"; auto expanded = "2001:0db8:0000:cd30:0000:0000:0000:0000"; - Chai::assert.equal(compressed, IPAddress::parse(expanded)->to_s()); - Chai::assert.equal("2001:db8::cd3", + assert.equal(compressed, IPAddress::parse(expanded)->to_s()); + assert.equal("2001:db8::cd3", IPAddress::parse("2001:0db8:0::cd3")->to_s()); - Chai::assert.equal("2001:db8::cd30", + assert.equal("2001:db8::cd30", IPAddress::parse("2001:0db8::cd30")->to_s()); - Chai::assert.equal("2001:db8::cd3", + assert.equal("2001:db8::cd3", IPAddress::parse("2001:0db8::cd3")->to_s()); }); it("test_classhmethod_parse_u128", []() { @@ -359,12 +360,12 @@ int main() { auto ip = i.first; auto num = i.second; // console.log(">>>>>>>>", i); - Chai::assert.equal(IPAddress::parse(ip)->to_s(), + assert.equal(IPAddress::parse(ip)->to_s(), Ipv6::from_int(num, 128)->to_s()); } }); it("test_classmethod_parse_hex", []() { - Chai::assert.equal(setup().ip.to_string(), + assert.equal(setup().ip.to_string(), Ipv6::from_str(setup().hex, 16, 64)->to_string()); }); }); diff --git a/cpp/test/test_ipv6_loopback.cpp b/cpp/test/test_ipv6_loopback.cpp index c78a5b5..8a8c764 100644 --- a/cpp/test/test_ipv6_loopback.cpp +++ b/cpp/test/test_ipv6_loopback.cpp @@ -1,5 +1,6 @@ -#include "chai.hpp" -#include "mocha.hpp" + +#include +using namespace cascara; #include "../src/ipaddress.hpp" #include "../src/prefix128.hpp" @@ -32,15 +33,15 @@ int main() { describe("ipv6_loopback", []() { it("test_attributes", []() { auto s = setup(); - Chai::assert.equal(128, s.ip.prefix.num); - Chai::assert.equal(true, s.ip.is_loopback()); - Chai::assert.equal(s.s, s.ip.to_s()); - Chai::assert.equal(s.n, s.ip.to_string()); - Chai::assert.equal(s.string, s.ip.to_string_uncompressed()); - Chai::assert.equal(s.one.toString(), s.ip.host_address.toString()); + assert.equal(128u, s.ip.prefix.num); + assert.equal(true, s.ip.is_loopback()); + assert.equal(s.s, s.ip.to_s()); + assert.equal(s.n, s.ip.to_string()); + assert.equal(s.string, s.ip.to_string_uncompressed()); + assert.equal(s.one.toString(), s.ip.host_address.toString()); }); it("test_method_ipv6", []() { - Chai::assert.equal(true, setup().ip.is_ipv6()); + assert.equal(true, setup().ip.is_ipv6()); }); }); return exit(); diff --git a/cpp/test/test_ipv6_mapped.cpp b/cpp/test/test_ipv6_mapped.cpp index c049c88..9ccc497 100644 --- a/cpp/test/test_ipv6_mapped.cpp +++ b/cpp/test/test_ipv6_mapped.cpp @@ -1,5 +1,6 @@ -#include "chai.hpp" -#include "mocha.hpp" + +#include +using namespace cascara; #include "../src/crunchy.hpp" #include "../src/ipaddress.hpp" @@ -50,13 +51,13 @@ int main() { describe("ipv6_mapped", []() { it("test_initialize", []() { auto s = setup(); - Chai::assert.isTrue(IPAddress::parse("::172.16.10.1").isOk()); + assert.isTrue(IPAddress::parse("::172.16.10.1").isOk()); for (auto i : s.valid_mapped) { auto ip = i.first; auto u128 = i.second; // println("-{}--{}", ip, u128); - Chai::assert.isTrue(IPAddress::parse(ip).isOk()); - Chai::assert.equal( + assert.isTrue(IPAddress::parse(ip).isOk()); + assert.equal( u128.toString(), IPAddress::parse(ip)->host_address.toString()); } @@ -64,8 +65,8 @@ int main() { auto ip = i.first; auto u128 = i.second; // println("===={}=={:x}", ip, u128); - Chai::assert.isTrue(IPAddress::parse(ip).isOk()); - Chai::assert.equal( + assert.isTrue(IPAddress::parse(ip).isOk()); + assert.equal( u128.toString(), IPAddress::parse(ip)->host_address.toString()); } @@ -74,20 +75,20 @@ int main() { for (auto i : setup().valid_mapped_ipv6_conversion) { auto ip6 = i.first; auto ip4 = i.second; - Chai::assert.equal(ip4, IPAddress::parse(ip6)->mapped->to_s()); + assert.equal(ip4, IPAddress::parse(ip6)->mapped->to_s()); } }); it("test_attributes", []() { auto s = setup(); - Chai::assert.equal(s.address, s.ip.to_string(), "to_string"); - Chai::assert.equal(128, s.ip.prefix.num, "prefix_num"); - Chai::assert.equal(s.s, s.ip.to_s_mapped(), "mapped"); - Chai::assert.equal(s.sstr, s.ip.to_string_mapped(), "mapped str"); - Chai::assert.equal(s.string, s.ip.to_string_uncompressed(), "uncompressed"); - Chai::assert.equal(s.u128.toString(), s.ip.host_address.toString(), "crunchy"); + assert.equal(s.address, s.ip.to_string(), "to_string"); + assert.equal(128, s.ip.prefix.num, "prefix_num"); + assert.equal(s.s, s.ip.to_s_mapped(), "mapped"); + assert.equal(s.sstr, s.ip.to_string_mapped(), "mapped str"); + assert.equal(s.string, s.ip.to_string_uncompressed(), "uncompressed"); + assert.equal(s.u128.toString(), s.ip.host_address.toString(), "crunchy"); }); - it("test_method_ipv6", []() { Chai::assert.isTrue(setup().ip.is_ipv6()); }); - it("test_mapped", []() { Chai::assert.isTrue(setup().ip.is_mapped()); }); + it("test_method_ipv6", []() { assert.isTrue(setup().ip.is_ipv6()); }); + it("test_mapped", []() { assert.isTrue(setup().ip.is_mapped()); }); }); return exit(); } diff --git a/cpp/test/test_ipv6_unspec.cpp b/cpp/test/test_ipv6_unspec.cpp index 96c40c9..8f3d488 100644 --- a/cpp/test/test_ipv6_unspec.cpp +++ b/cpp/test/test_ipv6_unspec.cpp @@ -1,5 +1,6 @@ -#include "chai.hpp" -#include "mocha.hpp" + +#include +using namespace cascara; #include "../src/crunchy.hpp" #include "../src/ipaddress.hpp" @@ -23,16 +24,16 @@ IPv6UnspecifiedTest setup() { return IPv6UnspecifiedTest(); } int main() { describe("ipv6_unspec", []() { it("test_attributes", []() { - Chai::assert.isTrue(setup().ip.host_address.eq(setup().num)); - Chai::assert.equal(128, setup().ip.prefix.num); - Chai::assert.equal(true, setup().ip.is_unspecified()); - Chai::assert.equal(setup().to_s, setup().ip.to_s()); - Chai::assert.equal(setup().to_string, setup().ip.to_string()); - Chai::assert.equal(setup().to_string_uncompressed, + assert.isTrue(setup().ip.host_address.eq(setup().num)); + assert.equal(128, setup().ip.prefix.num); + assert.equal(true, setup().ip.is_unspecified()); + assert.equal(setup().to_s, setup().ip.to_s()); + assert.equal(setup().to_string, setup().ip.to_string()); + assert.equal(setup().to_string_uncompressed, setup().ip.to_string_uncompressed()); }); it("test_method_ipv6", []() { - Chai::assert.equal(true, setup().ip.is_ipv6()); + assert.equal(true, setup().ip.is_ipv6()); }); }); return exit(); diff --git a/cpp/test/test_option.cpp b/cpp/test/test_option.cpp index e6514bd..b06534a 100644 --- a/cpp/test/test_option.cpp +++ b/cpp/test/test_option.cpp @@ -1,6 +1,7 @@ -#include "mocha.hpp" -#include "chai.hpp" + +#include +using namespace cascara; #include "../src/option.hpp" @@ -21,22 +22,22 @@ int main(int, char **) { it("default", [](){ auto none = Option(); - Chai::assert.isTrue(none.isNone()); - Chai::assert.isFalse(none.isSome()); + assert.isTrue(none.isNone()); + assert.isFalse(none.isSome()); try { none.unwrap(); - Chai::assert.isTrue(true, "unwrap should not work"); + assert.isTrue(true, "unwrap should not work"); } catch (OptionError e) { } }); it("None", [](){ auto none = None(); - Chai::assert.isTrue(none.isNone()); - Chai::assert.isFalse(none.isSome()); + assert.isTrue(none.isNone()); + assert.isFalse(none.isSome()); try { none.unwrap(); - Chai::assert.isTrue(true, "unwrap should not work"); + assert.isTrue(true, "unwrap should not work"); } catch (OptionError e) { } }); @@ -45,27 +46,27 @@ int main(int, char **) { TestOptional to; auto some = Some(to); to._42 = 8199; - Chai::assert.isFalse(some.isNone()); - Chai::assert.isTrue(some.isSome()); - Chai::assert.equal(some.unwrap()._42, 42); + assert.isFalse(some.isNone()); + assert.isTrue(some.isSome()); + assert.equal(some.unwrap()._42, 42); some.unwrap()._42 = 4711; - Chai::assert.equal(some.unwrap()._42, 4711); + assert.equal(some.unwrap()._42, 4711); }); it("Memory", [](){ TestOptional to; c_count = 0; { auto some = Some(to); - Chai::assert.equal(c_count, 1); - Chai::assert.equal(some.unwrap()._42, 42); + assert.equal(c_count, 1); + assert.equal(some.unwrap()._42, 42); } - Chai::assert.equal(c_count, 0, "loosing memory"); + assert.equal(c_count, 0, "loosing memory"); }); it("Ptr", [](){ TestOptional to; auto some = Some(to); - Chai::assert.equal(some->_42, 42); + assert.equal(some->_42, 42); }); }); diff --git a/cpp/test/test_prefix128.cpp b/cpp/test/test_prefix128.cpp index 08f7112..b55996a 100644 --- a/cpp/test/test_prefix128.cpp +++ b/cpp/test/test_prefix128.cpp @@ -1,5 +1,6 @@ -#include "chai.hpp" -#include "mocha.hpp" + +#include +using namespace cascara; #include "../src/prefix128.hpp" #include "../src/crunchy.hpp" @@ -24,8 +25,8 @@ class Prefix128Test { int main() { describe("prefix128", []() { it("test_initialize", []() { - Chai::assert.isTrue(Prefix128::create(129).isErr()); - Chai::assert.isTrue(Prefix128::create(64).isOk()); + assert.isTrue(Prefix128::create(129).isErr()); + assert.isTrue(Prefix128::create(64).isOk()); }); it("test_method_bits", []() { @@ -37,11 +38,11 @@ describe("prefix128", []() { for (auto i = 0; i < 64; ++i) { str << "0"; } - Chai::assert.equal(str.str(), prefix.bits()); + assert.equal(str.str(), prefix.bits()); }); it("test_method_to_u32", []() { for (auto hash : setup().u128_hash) { - Chai::assert.isTrue(hash.second.eq(Prefix128::create(hash.first)->netmask())); + assert.isTrue(hash.second.eq(Prefix128::create(hash.first)->netmask())); } }); }); diff --git a/cpp/test/test_prefix32.cpp b/cpp/test/test_prefix32.cpp index 33ad44d..968a8f2 100644 --- a/cpp/test/test_prefix32.cpp +++ b/cpp/test/test_prefix32.cpp @@ -1,6 +1,7 @@ -#include "chai.hpp" -#include "mocha.hpp" + +#include +using namespace cascara; #include "../src/prefix32.hpp" #include "../src/ipaddress.hpp" @@ -52,7 +53,7 @@ describe("prefix32", []() { it("test_attributes", []() { for (auto e : setup().prefix_hash) { auto prefix = Prefix32::create(e.second).unwrap(); - Chai::assert.equal(e.second, prefix.num); + assert.equal(e.second, prefix.num); } }); @@ -63,7 +64,7 @@ describe("prefix32", []() { // console.log(e); auto prefix = IPAddress::parse_netmask_to_prefix(netmask).unwrap(); //std::cout << netmask << ":" << num << ":" << prefix << std::endl; - Chai::assert.equal(num, prefix); + assert.equal(num, prefix); } }); it("test_method_to_ip", []() { @@ -71,47 +72,47 @@ describe("prefix32", []() { auto netmask = hash.first; auto num = hash.second; auto prefix = Prefix32::create(num).unwrap(); - Chai::assert.equal(netmask, prefix.to_ip_str()); + assert.equal(netmask, prefix.to_ip_str()); } }); it("test_method_to_s", []() { auto prefix = Prefix32::create(8).unwrap(); - Chai::assert.equal("8", prefix.to_s()); + assert.equal("8", prefix.to_s()); }); it("test_method_bits", []() { auto prefix = Prefix32::create(16).unwrap(); - Chai::assert.equal("11111111111111110000000000000000", prefix.bits()); + assert.equal("11111111111111110000000000000000", prefix.bits()); }); it("test_method_to_u32", []() { for (auto i : setup().u32_hash) { auto num = i.first; auto ip32 = i.second; - Chai::assert.isTrue(ip32.eq(Prefix32::create(num)->netmask())); + assert.isTrue(ip32.eq(Prefix32::create(num)->netmask())); } }); it("test_method_plus", []() { auto p1 = Prefix32::create(8).unwrap(); auto p2 = Prefix32::create(10).unwrap(); - Chai::assert.equal(18, p1.add_prefix(p2)->get_prefix()); - Chai::assert.equal(12, p1.add(4)->get_prefix()); + assert.equal(18, p1.add_prefix(p2)->get_prefix()); + assert.equal(12, p1.add(4)->get_prefix()); }); it("test_method_minus", []() { auto p1 = Prefix32::create(8).unwrap(); auto p2 = Prefix32::create(24).unwrap(); - Chai::assert.equal(16, p1.sub_prefix(p2)->get_prefix()); - Chai::assert.equal(16, p2.sub_prefix(p1)->get_prefix()); - Chai::assert.equal(20, p2.sub(4)->get_prefix()); + assert.equal(16, p1.sub_prefix(p2)->get_prefix()); + assert.equal(16, p2.sub_prefix(p1)->get_prefix()); + assert.equal(20, p2.sub(4)->get_prefix()); }); it("test_initialize", []() { - Chai::assert.isTrue(Prefix32::create(33).isErr()); - Chai::assert.isTrue(Prefix32::create(8).isOk()); + assert.isTrue(Prefix32::create(33).isErr()); + assert.isTrue(Prefix32::create(8).isOk()); }); it("test_method_octets", []() { for (auto i : setup().octets_hash) { auto arr = i.first; auto pref = i.second; auto prefix = Prefix32::create(pref).unwrap(); - Chai::assert.deepEqual(prefix.ip_bits->parts(prefix.netmask()), arr); + assert.deepEqual(prefix.ip_bits->parts(prefix.netmask()), arr); } }); it("test_method_brackets", []() { @@ -121,14 +122,14 @@ describe("prefix32", []() { auto prefix = Prefix32::create(pref).unwrap(); for (size_t index=0; index < arr.size(); ++index) { // console.log("xxxx", prefix.netmask()); - Chai::assert.equal(prefix.ip_bits->parts(prefix.netmask())[index], arr[index]); + assert.equal(prefix.ip_bits->parts(prefix.netmask())[index], arr[index]); } } }); it("test_method_hostmask", []() { auto prefix = Prefix32::create(8).unwrap(); // console.log(">>>>", prefix.host_mask()); - Chai::assert.equal("0.255.255.255", Ipv4::from_number(prefix.host_mask(), 0)->to_s()); + assert.equal("0.255.255.255", Ipv4::from_number(prefix.host_mask(), 0)->to_s()); }); }); return exit(); diff --git a/cpp/test/test_result.cpp b/cpp/test/test_result.cpp index c394e35..32adf2d 100644 --- a/cpp/test/test_result.cpp +++ b/cpp/test/test_result.cpp @@ -1,6 +1,6 @@ -#include "mocha.hpp" -#include "chai.hpp" +#include +using namespace cascara; #include "../src/result.hpp" @@ -18,12 +18,12 @@ int main(int, char **) { it("Error", [](){ auto err = Err("testcase"); - Chai::assert.isTrue(err.isErr()); - Chai::assert.isFalse(err.isOk()); - Chai::assert.equal(err.text(), "testcase"); + assert.isTrue(err.isErr()); + assert.isFalse(err.isOk()); + assert.equal(err.text(), "testcase"); try { err.unwrap(); - Chai::assert.isTrue(true, "unwrap should not work"); + assert.isTrue(true, "unwrap should not work"); } catch (OptionError e) { } }); @@ -31,21 +31,21 @@ int main(int, char **) { it("Some", [](){ TestOptional to; auto some = Ok(to); - Chai::assert.isFalse(some.isErr()); - Chai::assert.isTrue(some.isOk()); - Chai::assert.equal(some.unwrap()._42, 42); + assert.isFalse(some.isErr()); + assert.isTrue(some.isOk()); + assert.equal(some.unwrap()._42, 42); some.unwrap()._42 = 4711; - Chai::assert.equal(some.unwrap()._42, 4711); + assert.equal(some.unwrap()._42, 4711); }); it("Ptr", [](){ TestOptional to; auto some = Ok(to); - Chai::assert.isFalse(some.isErr()); - Chai::assert.isTrue(some.isOk()); - Chai::assert.equal(some->_42, 42); + assert.isFalse(some.isErr()); + assert.isTrue(some.isOk()); + assert.equal(some->_42, 42); some->_42 = 4711; - Chai::assert.equal(some->_42, 4711); + assert.equal(some->_42, 4711); }); diff --git a/cpp/test/test_rle.cpp b/cpp/test/test_rle.cpp index 93ebdea..3d811ed 100644 --- a/cpp/test/test_rle.cpp +++ b/cpp/test/test_rle.cpp @@ -1,5 +1,6 @@ -#include "chai.hpp" -#include "mocha.hpp" + +#include +using namespace cascara; #include #include @@ -10,10 +11,10 @@ using namespace ipaddress; void assert_rle(std::vector left, std::vector right, const char *str) { // std::cout << str << std::endl; - Chai::assert.equal(left.size(), right.size(), "array size() missmatch"); + assert.equal(left.size(), right.size(), "array size() missmatch"); for (size_t i = 0; i < left.size(); ++i) { // std::cout << left[i] << "==" << right[i] << std::endl; - Chai::assert.isTrue(left[i].eq(right[i]), + assert.isTrue(left[i].eq(right[i]), ([str, i, left, right]() -> const char * { std::stringstream s2; s2 << str << "=>";