Skip to content

Commit

Permalink
58% passed
Browse files Browse the repository at this point in the history
  • Loading branch information
mabels committed Sep 9, 2016
1 parent 840051c commit 2be4f09
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 32 deletions.
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ language: rust
rust:
- 1.8.0

#before_install:
# - sudo apt-get -qq update
# - sudo apt-get install -y ruby
# - gem install rbtree
before_install:
- sudo apt-get -qq update
- sudo apt-get install -y libboost-all-dev cmake

install:
- rvm use ruby-2.0.0-p598
- gem install construqt-ipaddress
Expand All @@ -18,3 +18,5 @@ script:
- (cd rust && cargo build --release --verbose)
- (cd rust && cargo test --release --verbose)
- (cd js && npm install && npm test)
- (cd cpp && cmake -DCMAKE_BUILD_TYPE=Release . && make)
- (cd cpp && ctest --timeout 60)
1 change: 1 addition & 0 deletions cpp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
**/CMakeFiles/
**/CTestTestfile.cmake
**/cmake_install.cmake
libipaddress.*
13 changes: 5 additions & 8 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,11 @@ find_package(Threads REQUIRED)

include_directories(.)

add_executable(main main.cpp tunator.cpp tun_device.cpp if_addrs_macos.cpp if_addrs_linux.cpp)
add_dependencies(main SimpleWebSocketServer)
add_dependencies(main jsoncpp)
#target_link_libraries(main ${jsoncpp_LIBRARY_DIR})
target_link_libraries(main ${jsoncpp_LIBRARIES})
target_link_libraries(main ${Boost_LIBRARIES})
target_link_libraries(main ${OPENSSL_LIBRARIES})
target_link_libraries(main ${CMAKE_THREAD_LIBS_INIT})
file(GLOB SOURCES "src/*.cpp")
#add_library(ipaddress SHARED ${SOURCES})
add_library(ipaddress STATIC ${SOURCES})
target_link_libraries(ipaddress ${Boost_LIBRARIES})


enable_testing()
add_subdirectory(test)
12 changes: 12 additions & 0 deletions cpp/src/crunchy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ class Crunchy {
s2 << std::dec;
} else if (radix == 16) {
s2 << std::hex;
} else if (radix == 2) {
std::vector<size_t> bits;
auto my = this->num;
do {
size_t tmp = static_cast<size_t>(my&0x1);
bits.push_back(tmp);
my = my >> 1;
} while(my != 0);
for (int i = bits.size()-1; i >= 0; --i) {
s2 << bits[i];
}
return s2.str();
} else {
throw NotImplementedException();
}
Expand Down
33 changes: 23 additions & 10 deletions cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ include_directories(${Boost_INCLUDE_DIR})

find_package(Threads REQUIRED)

set ( PROJECT_LINK_LIBS libipaddress.a )
link_directories( .. )

#add_executable(test_crunchy, test_crunchy.cpp)
#add_test(test_crunchy test_crunchy)

Expand All @@ -29,42 +32,52 @@ add_test(test_option test_option)
add_executable(test_result test_result.cpp)
add_test(test_result test_result)

add_executable(test_rle test_rle.cpp ../src/rle.cpp)
add_executable(test_rle test_rle.cpp)
add_test(test_rle test_rle)
target_link_libraries(test_rle ${PROJECT_LINK_LIBS} )

add_executable(test_crunchy test_crunchy.cpp ../src/crunchy.cpp)
add_executable(test_crunchy test_crunchy.cpp)
add_test(test_crunchy test_crunchy)
target_link_libraries(test_crunchy ${PROJECT_LINK_LIBS} )

add_executable(test_prefix32 test_prefix32.cpp ../src/crunchy.cpp ../src/rle.cpp ../src/ipaddress.cpp ../src/ipv4.cpp)
add_executable(test_prefix32 test_prefix32.cpp)
add_test(test_prefix32 test_prefix32)
target_link_libraries(test_prefix32 ${Boost_LIBRARIES})
target_link_libraries(test_prefix32 ${PROJECT_LINK_LIBS} )

add_executable(test_prefix128 test_prefix128.cpp ../src/crunchy.cpp ../src/rle.cpp ../src/ipaddress.cpp ../src/ipv4.cpp)
add_executable(test_prefix128 test_prefix128.cpp)
add_test(test_prefix128 test_prefix128)
target_link_libraries(test_prefix128 ${Boost_LIBRARIES})
target_link_libraries(test_prefix128 ${PROJECT_LINK_LIBS} )


add_executable(test_ipv6_unspec test_ipv6_unspec.cpp ../src/crunchy.cpp ../src/rle.cpp ../src/ipaddress.cpp ../src/ipv4.cpp)
add_executable(test_ipv6_unspec test_ipv6_unspec.cpp)
add_test(test_ipv6_unspec test_ipv6_unspec)
target_link_libraries(test_ipv6_unspec ${Boost_LIBRARIES})
target_link_libraries(test_ipv6_unspec ${PROJECT_LINK_LIBS} )

add_executable(test_ipv6_mapped test_ipv6_mapped.cpp ../src/crunchy.cpp ../src/rle.cpp ../src/ipaddress.cpp ../src/ipv4.cpp)
add_executable(test_ipv6_mapped test_ipv6_mapped.cpp)
add_test(test_ipv6_mapped test_ipv6_mapped)
target_link_libraries(test_ipv6_mapped ${Boost_LIBRARIES})
target_link_libraries(test_ipv6_mapped ${PROJECT_LINK_LIBS} )

add_executable(test_ipv6_loopback test_ipv6_loopback.cpp ../src/crunchy.cpp ../src/rle.cpp ../src/ipaddress.cpp ../src/ipv4.cpp)
add_executable(test_ipv6_loopback test_ipv6_loopback.cpp)
add_test(test_ipv6_loopback test_ipv6_loopback)
target_link_libraries(test_ipv6_loopback ${Boost_LIBRARIES})
target_link_libraries(test_ipv6_loopback ${PROJECT_LINK_LIBS} )

add_executable(test_ipv6 test_ipv6.cpp ../src/crunchy.cpp ../src/rle.cpp ../src/ipaddress.cpp ../src/ipv4.cpp)
add_executable(test_ipv6 test_ipv6.cpp)
add_test(test_ipv6 test_ipv6)
target_link_libraries(test_ipv6 ${Boost_LIBRARIES})
target_link_libraries(test_ipv6 ${PROJECT_LINK_LIBS} )

add_executable(test_ipv4 test_ipv4.cpp ../src/crunchy.cpp ../src/rle.cpp ../src/ipaddress.cpp ../src/ipv4.cpp)
add_executable(test_ipv4 test_ipv4.cpp)
add_test(test_ipv4 test_ipv4)
target_link_libraries(test_ipv4 ${Boost_LIBRARIES})
target_link_libraries(test_ipv4 ${PROJECT_LINK_LIBS} )


add_executable(test_ipaddress test_ipaddress.cpp ../src/crunchy.cpp ../src/ipaddress.cpp ../src/ipv4.cpp ../src/rle.cpp)
add_executable(test_ipaddress test_ipaddress.cpp)
add_test(test_ipaddress test_ipaddress)
target_link_libraries(test_ipaddress ${Boost_LIBRARIES})
target_link_libraries(test_ipaddress ${PROJECT_LINK_LIBS} )
22 changes: 14 additions & 8 deletions cpp/test/chai.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,36 @@ namespace Chai {

class Assert {
public:
void isTrue(bool v, const char *msg = "") const {
size_t count = 0;
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 = "") const {
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 = "") const {
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 = "") const {
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 = "") const {
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 = "") const {
void equal(unsigned char t1, unsigned char t2, const char *msg = "") {
++count;
if (t1 != t2) {
std::stringstream s2;
s2 << "uchar is not equal ";
Expand All @@ -59,7 +63,8 @@ namespace Chai {
}

}
template<typename T> void equal(T t1, T t2, const char *msg = "") const {
template<typename T> void equal(T t1, T t2, const char *msg = "") {
++count;
if (t1 != t2) {
std::stringstream s2;
s2 << "is not equal ";
Expand Down Expand Up @@ -109,7 +114,8 @@ namespace Chai {
return s2.str();
}

template<typename T> void deepEqual(std::vector<T> left, std::vector<T> right, const char *msg = "") const {
template<typename T> void deepEqual(std::vector<T> left, std::vector<T> right, const char *msg = "") {
++count;
std::stringstream s2;
s2 << "array size() missmatch:" << msg << ":" <<
Assert::vec_to_string(0, left) << "====" <<
Expand Down
6 changes: 4 additions & 2 deletions cpp/test/mocha.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <iostream>
#include <exception>
#include "chai.hpp"
#include <stdlib.h>

typedef std::function<void()> MochaAction;

Expand All @@ -13,8 +14,9 @@ static int okCount = 0;
int exit() {
std::cout << std::dec << std::endl << "Total " << okCount+failCount
<< " Ok " << okCount
<< " Fail " << failCount << std::endl;
return failCount;
<< " Fail " << failCount
<< " Assertions " << Chai::assert.count << std::endl;
std::exit(std::min(failCount, 27));
}

void describe(const char *title, MochaAction action) {
Expand Down
1 change: 1 addition & 0 deletions cpp/test/test_ipaddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,5 @@ int main() {
Chai::assert.equal("10.0.1.1/24", a2.to_string());
});
});
return exit();
}
1 change: 1 addition & 0 deletions cpp/test/test_ipv4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,4 +628,5 @@ int main() {
Chai::assert.isTrue(Ipv4::parse_classful("192.168.256.257").isErr());
});
});
return exit();
}
1 change: 1 addition & 0 deletions cpp/test/test_ipv6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,5 @@ int main() {
Ipv6::from_str(setup().hex, 16, 64).unwrap().to_string());
});
});
return exit();
}
1 change: 1 addition & 0 deletions cpp/test/test_ipv6_loopback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ int main() {
Chai::assert.equal(true, setup().ip.is_ipv6());
});
});
return exit();
}
1 change: 1 addition & 0 deletions cpp/test/test_ipv6_mapped.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,5 @@ int main() {
it("test_method_ipv6", []() { Chai::assert.isTrue(setup().ip.is_ipv6()); });
it("test_mapped", []() { Chai::assert.isTrue(setup().ip.is_mapped()); });
});
return exit();
}
1 change: 1 addition & 0 deletions cpp/test/test_ipv6_unspec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ int main() {
Chai::assert.equal(true, setup().ip.is_ipv6());
});
});
return exit();
}
1 change: 1 addition & 0 deletions cpp/test/test_prefix128.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ describe("prefix128", []() {
}
});
});
return exit();
}
2 changes: 2 additions & 0 deletions cpp/test/test_prefix32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe("prefix32", []() {
auto num = e.second;
// console.log(e);
auto prefix = IPAddress::parse_netmask_to_prefix(netmask).unwrap();
std::cout << netmask << ":" << num << ":" << prefix;
Chai::assert.equal(num, prefix);
}
});
Expand Down Expand Up @@ -128,4 +129,5 @@ describe("prefix32", []() {
Chai::assert.equal("0.255.255.255", Ipv4::from_number(prefix.host_mask(), 0).unwrap().to_s());
});
});
return exit();
}
1 change: 1 addition & 0 deletions cpp/test/test_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ int main(int, char **) {
});

});
return exit();
}

0 comments on commit 2be4f09

Please sign in to comment.