-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.cc
97 lines (90 loc) · 2.28 KB
/
test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "gtest/gtest.h"
#include "timevalue.h"
#include "timer.h"
#include "moduleinfo.h"
#include "keyboardmanager.h"
#include "keyboardmessagehelper.h"
#include "matrixmanager.h"
#include "serialkeyboard.h"
#include <algorithm>
#include <queue>
#include <tinyxml.h>
#include "log.h"
using namespace std;
bool LogInitializer::bInitialized = LogInitializer::init();
TEST(ModuleInfo, Test)
{
ModuleInfo info;
EXPECT_THROW(info.name(), runtime_error);
info.open("./Module.xml");
cout<<info.name()<<endl;
cout<<info.type()<<endl;
cout<<info.author()<<endl;
cout<<info.version()<<endl;
cout<<info.date()<<endl;
cout<<info.attribute("baudrate", 4800l) + 1000<<endl;
cout<<info.attribute("parity", string("E"))<<endl;
cout<<info.attribute("useThread", false)<<endl;
string buf;
info.encode(buf);
cout<<buf;
}
TEST(MatrixManager, Test)
{
int handle;
MatrixManager mgr("./modules/");
char path[] = "/dev/ttyUSB0";
ASSERT_NE((handle = mgr.loadMatrix("matrixcz08", NULL, path)), -1);
Matrix* mt = mgr.getMatrix();
ASSERT_NE(mt, (Matrix*)NULL);
Message *msg = KeyboardMessageHelper::buildSwitchMessage(0, -1, 1, 1);
ASSERT_NE(msg, (Message*)NULL);
mt->post(msg);
sleep(1);
mgr.unloadMatrix();
}
TEST(KeyboardManager, Test)
{
Keyboard::Id handle, handle2;
KeyboardManager mgr("./modules/");
char path[] = "/dev/ttyUSB0";
char path1[] = "/dev/ttyS0";
ASSERT_NE((handle = mgr.loadKeyboard("keyboardhoneywell", NULL, path)), 0);
ASSERT_NE((handle2 = mgr.loadKeyboard("keyboardjxj", NULL, path1)), 0);
Keyboard* kb = mgr.getKeyboard(handle);
ASSERT_NE(kb, (Keyboard*)NULL);
kb = mgr.getKeyboard(handle2);
ASSERT_NE(kb, (Keyboard*)NULL);
ASSERT_EQ(kb->user().priority(), User::LowestPriority);
mgr.unloadKeyboard(handle);
mgr.unloadKeyboard(handle2);
}
class TestListener : public SerialPortListener {
public:
virtual int onReadable(SerialPort& sp) {
char buf[32];
int len = sp.read(buf, sizeof(buf));
for(int i=0;i<len;++i)
{
cout<<buf[i];
cout.flush();
}
cout<<endl;
return 0;
}
virtual int onExcept(SerialPort&) {
return 0;
}
};
TEST(SerialPort, Test)
{
char msg[] = "hello world!";
TestListener listener;
SerialPort sp;
sp.addListener(&listener);
sp.open("/dev/ttyUSB0", 9600, 8, 1, 'N');
sleep(1);
sp.write(msg, sizeof(msg));
sleep(1);
sp.close();
}