Skip to content

Commit

Permalink
initial unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
melode11 committed Apr 18, 2015
1 parent 95c3d47 commit 9b2556e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 126 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build/
**/*.user
7 changes: 7 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 2.8)
include(${CMAKE_CURRENT_SOURCE_DIR}/../CMakeLists.txt)
find_package(Boost ${BOOST_VER} REQUIRED COMPONENTS unit_test_framework)
add_executable(sio_test sio_test.cpp)
target_link_libraries(sioclient PRIVATE ${Boost_LIBRARIES})
target_link_libraries(sio_test sioclient)
target_include_directories(sio_test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../src" ${Boost_INCLUDE_DIRS} )
4 changes: 4 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Use following instruction to build.
```bash
cmake -DBOOST_LIB=D:\boost_1_57_0\boost_1_57_0\build\lib -DBOOST_INCLUDE=D:\boost_1_57_0\boost_1_57_0 -DBOOST_VER:STRING=1.57.0 -DCMAKE_BUILD_TYPE=Debug ./
```
48 changes: 48 additions & 0 deletions test/sio_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// sio_test_sample.cpp
//
// Created by Melo Yao on 3/24/15.
//

#include <sio_client.h>
#include <internal/sio_packet.h>
#include <functional>
#include <iostream>
#include <thread>

#define BOOST_TEST_MODULE sio_test
#include <boost/test/unit_test.hpp>

using namespace sio;
BOOST_AUTO_TEST_SUITE(packet_test)

BOOST_AUTO_TEST_CASE( packet_test_construct_1 )
{
packet p("nsp",nullptr,1001,true);
BOOST_CHECK(p.get_frame() == packet::frame_message);
BOOST_CHECK(p.get_message() == nullptr);
BOOST_CHECK(p.get_nsp() == std::string("nsp"));
BOOST_CHECK(p.get_pack_id() == 1001);
}

BOOST_AUTO_TEST_CASE( packet_test_construct_2 )
{
packet p(packet::frame_ping);
BOOST_CHECK(p.get_frame() == packet::frame_ping);
BOOST_CHECK(p.get_message() == nullptr);
BOOST_CHECK(p.get_nsp() == std::string(""));
BOOST_CHECK(p.get_pack_id() == 0xFFFFFFFF);
}

BOOST_AUTO_TEST_CASE( packet_test_construct_3 )
{
packet p(packet::type_connect,"nsp",nullptr);
BOOST_CHECK(p.get_frame() == packet::frame_message);
BOOST_CHECK(p.get_type() == packet::type_connect);
BOOST_CHECK(p.get_message() == nullptr);
BOOST_CHECK(p.get_nsp() == std::string("nsp"));
BOOST_CHECK(p.get_pack_id() == 0xFFFFFFFF);
}

BOOST_AUTO_TEST_SUITE_END()

126 changes: 0 additions & 126 deletions test/sio_test_sample.cpp

This file was deleted.

0 comments on commit 9b2556e

Please sign in to comment.