Improve unit tests coverage
[platform/core/appfw/shortcut.git] / tests / unit_tests / src / test_shortcut_db.cc
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <shortcut_db.h>
17 #include <shortcut_private.h>
18 #include <gtest/gtest.h>
19
20 #include "system_info_mock.h"
21 #include "gio_mock.h"
22 #include "test_fixture.h"
23
24 class Mocks : public ::testing::NiceMock<SystemInfoMock>,
25               public ::testing::NiceMock<GioMock> {};
26
27 class ShortcutDbTest : public TestFixture {
28  public:
29   ShortcutDbTest() : TestFixture(std::make_unique<Mocks>()) {}
30   virtual ~ShortcutDbTest() {}
31   virtual void SetUp() {}
32   virtual void TearDown() {}
33 };
34
35 TEST_F(ShortcutDbTest, Init) {
36     int r = shortcut_db_init();
37     EXPECT_EQ(SHORTCUT_ERROR_IO_ERROR, r);
38
39     GList* list = nullptr;
40     r = shortcut_db_get_list("not_working", &list);
41     EXPECT_EQ(SHORTCUT_ERROR_IO_ERROR, r);
42
43     r = shortcut_set_db_path("./db.db");
44     EXPECT_EQ(SHORTCUT_ERROR_NONE, r);
45
46     r = shortcut_db_init();
47     EXPECT_EQ(SHORTCUT_ERROR_NONE, r);
48
49     r = shortcut_db_get_list("working", &list);
50     EXPECT_EQ(SHORTCUT_ERROR_NONE, r);
51     EXPECT_EQ(nullptr, list);
52 }