using ::testing::SetArgPointee;
using ::testing::Return;
+static char** __create_table(void) {
+ char** table = (char** )calloc(10, sizeof(char*));
+ table[0] = strdup("pkgname");
+ if (table[0] == nullptr)
+ goto out;
+
+ table[1] = strdup("apppath");
+ if (table[1] == nullptr)
+ goto out;
+
+ table[2] = strdup("arg");
+ if (table[2] == nullptr)
+ goto out;
+
+ table[3] = strdup("122232");
+ if (table[3] == nullptr)
+ goto out;
+
+ table[4] = strdup("instance_id");
+ if (table[4] == nullptr)
+ goto out;
+
+ table[5] = strdup("instance_name");
+ if (table[5] == nullptr)
+ goto out;
+
+ table[6] = strdup("icon");
+ if (table[6] == nullptr)
+ goto out;
+
+ table[7] = strdup("uri");
+ if (table[7] == nullptr)
+ goto out;
+
+ table[8] = strdup("image");
+ if (table[8] == nullptr)
+ goto out;
+
+ table[9] = strdup("compid");
+ if (table[9] == nullptr)
+ goto out;
+
+ return table;
+
+out:
+ for (int i = 0; i < 10; i++) {
+ if (table[i])
+ free(table[i]);
+ }
+
+ free(table);
+ return nullptr;
+}
+
class Mocks : public ::testing::NiceMock<AulMock>,
public ::testing::NiceMock<GioMock>,
public ::testing::NiceMock<SqlMock> {};
virtual ~RuaTest() {}
virtual void SetUp() {
+ table_ = __create_table();
}
virtual void TearDown() {
+ if (table_) {
+ for (int i = 0; i < 10; i++)
+ free(table_[i]);
+ free(table_);
+ }
}
+ char** table_ = nullptr;
};
static void __rua_history_update_cb(char** table, int nrows, int ncols,
EXPECT_NE(ret, 0);
}
-static char** __create_table(void) {
- char** table = (char** )calloc(10, sizeof(char*));
- table[0] = strdup("pkgname");
- if (table[0] == nullptr)
- goto out;
-
- table[1] = strdup("apppath");
- if (table[1] == nullptr)
- goto out;
-
- table[2] = strdup("arg");
- if (table[2] == nullptr)
- goto out;
-
- table[3] = strdup("122232");
- if (table[3] == nullptr)
- goto out;
-
- table[4] = strdup("instance_id");
- if (table[4] == nullptr)
- goto out;
-
- table[5] = strdup("instance_name");
- if (table[5] == nullptr)
- goto out;
-
- table[6] = strdup("icon");
- if (table[6] == nullptr)
- goto out;
-
- table[7] = strdup("uri");
- if (table[7] == nullptr)
- goto out;
-
- table[8] = strdup("image");
- if (table[8] == nullptr)
- goto out;
-
- table[9] = strdup("compid");
- if (table[9] == nullptr)
- goto out;
-
- return table;
-
-out:
- for (int i = 0; i < 10; i++) {
- if (table[i])
- free(table[i]);
- }
-
- free(table);
- return nullptr;
-}
-
TEST_F(RuaTest, rua_history_get_rec) {
- char** table = __create_table();
- ASSERT_TRUE(table != nullptr);
+ ASSERT_TRUE(table_ != nullptr);
EXPECT_CALL(GetMock<SqlMock>(),
sqlite3_open_v2(_, _, _, _)).WillOnce(Return(0));
sqlite3_busy_handler(_, _, _)).WillOnce(Return(0));
EXPECT_CALL(GetMock<SqlMock>(),
sqlite3_get_table(_, _, _, _, _, _)).
- WillOnce(DoAll(SetArgPointee<2>(table),
+ WillOnce(DoAll(SetArgPointee<2>(table_),
SetArgPointee<3>(1),
SetArgPointee<4>(0), (Return(0))));
EXPECT_EQ(ret, 0);
rua_history_unload_db(&get_table);
-
- for (int i = 0; i < 10; i++)
- free(table[i]);
- free(table);
}
TEST_F(RuaTest, rua_is_latest_app_N) {