hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MainMySQLTestsFile.cpp
Go to the documentation of this file.
1 #include <MySQLSessionTests.h>
2 #include <SQLiteSessionTests.h>
3 
4 /*
5  * MySQL tests
6  */
7 TEST (MySQLSessionTest,CheckMySQLConnectionWithCorrectConnectionParameters) {
8  MySQLSessionTests mysql;
9  ASSERT_NO_THROW(mysql.setConnection(MYSQL_KEY,CORRECT_PARAMETERS_MySQL));
10  bool isConnected = false;
11  isConnected = mysql.isConnected();
12  EXPECT_EQ (isConnected,true);
13  ASSERT_NO_THROW(mysql.closeConnection());
14 }
15 
16 TEST (MySQLSessionTest,CheckMySQLConnectionWithIncorrectConnectionParameters) {
17  MySQLSessionTests mysql;
18  ASSERT_THROW(mysql.setConnection(MYSQL_KEY,INCORRECT_PARAMETERS_MySQL), Poco::Exception);
19 }
20 
21 TEST_F (MySQLSessionTests,insertTupleInDataBase) {
24  std::vector<person>::const_iterator it = people.begin();
25  EXPECT_EQ (it->get<0>(),1);
26  EXPECT_STREQ (it->get<1>().c_str(),"Person1");
27  ++it; //go to the next element
28  EXPECT_EQ (it->get<0>(),2);
29  EXPECT_STREQ (it->get<1>().c_str(),"Person2");
30 }
31 
32 TEST_F (MySQLSessionTests,selectOneFieldFromDataBase) {
35  std::vector<person_name>::const_iterator it = namesOfPersons.begin();
36  EXPECT_STREQ (it->get<0>().c_str(),"Person1");
37  ++it; //go to the next element
38  EXPECT_STREQ (it->get<0>().c_str(),"Person2");
39 }
40 
41 TEST_F (MySQLSessionTests,CountDataInEmptyDataBase) {
42  int count = -1;
43  ASSERT_NO_THROW(MySQLSessionTests::countDataInDataBase (count));
44  EXPECT_EQ (count,0);
45 }
46 
47 TEST_F (MySQLSessionTests,CountDataInDataBase) {
48  int count = -1;
50  ASSERT_NO_THROW(MySQLSessionTests::countDataInDataBase(count));
51  EXPECT_EQ (count,2);
52 }
53 
54 TEST_F (MySQLSessionTests,DeleteDataFromDataBase) {
56  ASSERT_NO_THROW (MySQLSessionTests::clearDataBase ());
57  int count = -1;
59  EXPECT_EQ (count,0);
60 }
61 
62 TEST_F (MySQLSessionTests,UseTypeHandler) {
65  std::vector<Object>::const_iterator it = objects.begin();
66  EXPECT_EQ (it->id,3);
67  EXPECT_STREQ (it->name.c_str(),"Object3");
68 }
69 /*
70  * end MySQL tests
71  */
72 
73 /*
74  * SQLite tests
75  */
76 TEST (SQLiteSessionTest,CheckSQLiteConnectionWithCorrectConnectionParameters) {
77  SQLiteSessionTests sqlite;
78  ASSERT_NO_THROW(sqlite.setConnection(SQLITE_KEY,CORRECT_PARAMETERS_SQLite));
79  bool isConnected = false;
80  isConnected = sqlite.isConnected();
81  EXPECT_EQ (isConnected,true);
82  ASSERT_NO_THROW(sqlite.closeConnection());
83 }
84 
85 TEST_F (SQLiteSessionTests,insertTupleInDataBase) {
88  std::vector<person>::const_iterator it = people.begin();
89  EXPECT_EQ (it->get<0>(),1);
90  EXPECT_STREQ (it->get<1>().c_str(),"Person1");
91  ++it; //go to the next element
92  EXPECT_EQ (it->get<0>(),2);
93  EXPECT_STREQ (it->get<1>().c_str(),"Person2");
94 }
95 
96 TEST_F (SQLiteSessionTests,selectOneFieldFromDataBase) {
99  std::vector<person_name>::const_iterator it = namesOfPersons.begin();
100  EXPECT_STREQ (it->get<0>().c_str(),"Person1");
101  ++it; //go to the next element
102  EXPECT_STREQ (it->get<0>().c_str(),"Person2");
103 }
104 
105 TEST_F (SQLiteSessionTests,CountDataInEmptyDataBase) {
106  int count = -1;
107  ASSERT_NO_THROW(SQLiteSessionTests::countDataInDataBase (count));
108  EXPECT_EQ (count,0);
109 }
110 
111 TEST_F (SQLiteSessionTests,CountDataInDataBase) {
112  int count = -1;
114  ASSERT_NO_THROW(SQLiteSessionTests::countDataInDataBase(count));
115  EXPECT_EQ (count,2);
116 }
117 
118 TEST_F (SQLiteSessionTests,DeleteDataFromDataBase) {
120  ASSERT_NO_THROW (SQLiteSessionTests::clearDataBase ());
121  int count = -1;
123  EXPECT_EQ (count,0);
124 }
125 
126 TEST_F (SQLiteSessionTests,UseTypeHandler) {
129  std::vector<Object>::const_iterator it = objects.begin();
130  EXPECT_EQ (it->id,3);
131  EXPECT_STREQ (it->name.c_str(),"Object3");
132 }
133 /*
134  * end SQLite tests
135  */
136 
137 int main(int argc, char **argv) {
138  ::testing::InitGoogleTest(&argc, argv);
139  return RUN_ALL_TESTS();
140 }