Skip to content

Commit 9b2556e

Browse files
committed
initial unit test
1 parent 95c3d47 commit 9b2556e

File tree

5 files changed

+60
-126
lines changed

5 files changed

+60
-126
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
build/
2+
**/*.user

test/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cmake_minimum_required(VERSION 2.8)
2+
include(${CMAKE_CURRENT_SOURCE_DIR}/../CMakeLists.txt)
3+
find_package(Boost ${BOOST_VER} REQUIRED COMPONENTS unit_test_framework)
4+
add_executable(sio_test sio_test.cpp)
5+
target_link_libraries(sioclient PRIVATE ${Boost_LIBRARIES})
6+
target_link_libraries(sio_test sioclient)
7+
target_include_directories(sio_test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../src" ${Boost_INCLUDE_DIRS} )

test/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Use following instruction to build.
2+
```bash
3+
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 ./
4+
```

test/sio_test.cpp

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// sio_test_sample.cpp
3+
//
4+
// Created by Melo Yao on 3/24/15.
5+
//
6+
7+
#include <sio_client.h>
8+
#include <internal/sio_packet.h>
9+
#include <functional>
10+
#include <iostream>
11+
#include <thread>
12+
13+
#define BOOST_TEST_MODULE sio_test
14+
#include <boost/test/unit_test.hpp>
15+
16+
using namespace sio;
17+
BOOST_AUTO_TEST_SUITE(packet_test)
18+
19+
BOOST_AUTO_TEST_CASE( packet_test_construct_1 )
20+
{
21+
packet p("nsp",nullptr,1001,true);
22+
BOOST_CHECK(p.get_frame() == packet::frame_message);
23+
BOOST_CHECK(p.get_message() == nullptr);
24+
BOOST_CHECK(p.get_nsp() == std::string("nsp"));
25+
BOOST_CHECK(p.get_pack_id() == 1001);
26+
}
27+
28+
BOOST_AUTO_TEST_CASE( packet_test_construct_2 )
29+
{
30+
packet p(packet::frame_ping);
31+
BOOST_CHECK(p.get_frame() == packet::frame_ping);
32+
BOOST_CHECK(p.get_message() == nullptr);
33+
BOOST_CHECK(p.get_nsp() == std::string(""));
34+
BOOST_CHECK(p.get_pack_id() == 0xFFFFFFFF);
35+
}
36+
37+
BOOST_AUTO_TEST_CASE( packet_test_construct_3 )
38+
{
39+
packet p(packet::type_connect,"nsp",nullptr);
40+
BOOST_CHECK(p.get_frame() == packet::frame_message);
41+
BOOST_CHECK(p.get_type() == packet::type_connect);
42+
BOOST_CHECK(p.get_message() == nullptr);
43+
BOOST_CHECK(p.get_nsp() == std::string("nsp"));
44+
BOOST_CHECK(p.get_pack_id() == 0xFFFFFFFF);
45+
}
46+
47+
BOOST_AUTO_TEST_SUITE_END()
48+

test/sio_test_sample.cpp

-126
This file was deleted.

0 commit comments

Comments
 (0)