forked from yedf2/handy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yedf
committed
Jun 15, 2015
1 parent
3ea91fe
commit 1f95f0e
Showing
22 changed files
with
501 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#include "port_posix.h" | ||
#include <netdb.h> | ||
#include <string.h> | ||
|
||
namespace handy { | ||
namespace port{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <handy/conf.h> | ||
#include <string.h> | ||
#include "test_harness.h" | ||
|
||
using namespace std; | ||
using namespace handy; | ||
|
||
int dump_ini(const char* dir, const char* inifile) { | ||
Conf conf; | ||
char buf[4096]; | ||
snprintf(buf, sizeof buf, "%s/%s", dir, inifile); | ||
int err = conf.parse(buf); | ||
if (err) { | ||
//printf("parse error in %s err: %d\n", inifile, err); | ||
return err; | ||
} | ||
//printf("file %s:\n", inifile); | ||
//for (auto& kv : conf.values_) { | ||
// for(auto& v : kv.second) { | ||
// printf("%s=%s\n", kv.first.c_str(), v.c_str()); | ||
// } | ||
//} | ||
return 0; | ||
} | ||
|
||
TEST(test::TestBase, allFiles) { | ||
const char* dir = "./"; | ||
ASSERT_EQ(1, dump_ini(dir, "files/bad_comment.ini")); | ||
ASSERT_EQ(1, dump_ini(dir, "files/bad_multi.ini")); | ||
ASSERT_EQ(3, dump_ini(dir, "files/bad_section.ini")); | ||
ASSERT_EQ(0, dump_ini(dir, "files/multi_line.ini")); | ||
ASSERT_EQ(0, dump_ini(dir, "files/normal.ini")); | ||
ASSERT_EQ(0, dump_ini(dir, "files/user_error.ini")); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is an error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
indented |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[section1] | ||
name1=value1 | ||
[section2 | ||
[section3 ; comment ] | ||
name2=value2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[section1] | ||
single1 = abc | ||
multi = this is a | ||
multi-line value | ||
single2 = xyz | ||
[section2] | ||
multi = a | ||
b | ||
c | ||
[section3] | ||
single: ghi | ||
multi: the quick | ||
brown fox | ||
name = bob smith ; comment line 1 | ||
; comment line 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
; This is an INI file | ||
[section1] ; section comment | ||
one=This is a test ; name=value comment | ||
two = 1234 | ||
; x=y | ||
|
||
[ section 2 ] | ||
happy = 4 | ||
sad = | ||
|
||
[empty] | ||
; do nothing | ||
|
||
[comment_test] | ||
test1 = 1;2;3 ; only this will be a comment | ||
test2 = 2;3;4;this won't be a comment, needs whitespace before ';' | ||
test;3 = 345 ; key should be "test;3" | ||
test4 = 4#5#6 ; '#' only starts a comment at start of line | ||
#test5 = 567 ; entire line commented | ||
# test6 = 678 ; entire line commented, except in MULTILINE mode | ||
|
||
[colon_tests] | ||
Content-Type: text/html | ||
foo:bar | ||
adams : 42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[section] | ||
a = b | ||
user = parse_error | ||
c = d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include <handy/conn.h> | ||
#include <handy/logging.h> | ||
#include "test_harness.h" | ||
#include <thread> | ||
|
||
using namespace std; | ||
using namespace handy; | ||
|
||
TEST(test::TestBase, Ip4Addr) { | ||
ASSERT_EQ("127.0.0.1:80", Ip4Addr("localhost", 80).toString()); | ||
ASSERT_EQ(true, Ip4Addr("www.baidu.com", 80).isIpValid()); | ||
ASSERT_EQ(Ip4Addr("127...", 80).isIpValid(), false); | ||
ASSERT_EQ(true, Ip4Addr("127.0.0.1", 80).isIpValid()); | ||
} | ||
|
||
TEST(test::TestBase, EventBase) { | ||
Logger::getLogger().setLogLevel(Logger::LDEBUG); | ||
EventBase base; | ||
base.safeCall([] { | ||
info("task by base.addTask"); | ||
}); | ||
thread th([&]{ usleep(50000); info("base exit"); base.exit(); }); | ||
base.loop(); | ||
th.join(); | ||
} | ||
|
||
TEST(test::TestBase, Timer) { | ||
EventBase base; | ||
long now = util::timeMilli(); | ||
info("adding timers "); | ||
TimerId tid1 = base.runAt(now + 100, []{info("timer at 100");}); | ||
TimerId tid2 = base.runAfter(50, []{ info("timer after 50"); }); | ||
TimerId tid3 = base.runAfter(20, [] { info("timer interval 10");}, 10); | ||
base.runAfter(120, [&] { | ||
info("after 120 then cancel above"); | ||
base.cancel(tid1); | ||
base.cancel(tid2); | ||
base.cancel(tid3); | ||
base.exit(); | ||
}); | ||
base.loop(); | ||
} | ||
|
||
TEST(test::TestBase, TcpServer1) { | ||
Logger::getLogger().setLogLevel(Logger::LDEBUG); | ||
EventBase base; | ||
ThreadPool th(2); | ||
TcpServer delayEcho(&base, "", 99); | ||
delayEcho.onConnRead( | ||
[&th, &base](const TcpConnPtr& con) { | ||
th.addTask([&base,con] { | ||
usleep(200*1000); | ||
info("in pool"); | ||
base.safeCall([con, &base]{ | ||
con->send(con->getInput()); | ||
base.exit(); | ||
}); | ||
}); | ||
con->close(); | ||
} | ||
); | ||
TcpConnPtr con = TcpConn::createConnection(&base, "localhost", 99); | ||
con->onState([](const TcpConnPtr& con) { | ||
if (con->getState() == TcpConn::Connected) | ||
con->send("hello"); | ||
}); | ||
base.loop(); | ||
th.exit(); | ||
th.join(); | ||
Logger::getLogger().setLogLevel(Logger::LINFO); | ||
} |
Oops, something went wrong.