PKG_CHECK_MODULES(SQLITE_DEPS REQUIRED sqlite3)
PKG_CHECK_MODULES(GOBJECT_DEPS REQUIRED gobject-2.0)
+FIND_PACKAGE(Boost REQUIRED COMPONENTS filesystem)
+
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(test)
Source1001: %{name}.manifest
Source1002: %{name}.service
Source1003: %{name}.conf
+BuildRequires: boost-devel
BuildRequires: cmake
BuildRequires: pkgconfig(bundle)
BuildRequires: pkgconfig(dlog)
TARGET_INCLUDE_DIRECTORIES(${TARGET_TIZEN_THEME_PLUGIN} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}../)
APPLY_PKG_CONFIG(${TARGET_TIZEN_THEME_PLUGIN} PUBLIC
+ Boost
GLIB_DEPS
JSONCPP_DEPS
PKGMGR_INFO_DEPS
#include <algorithm>
#include <string>
+#include <boost/filesystem.hpp>
+
#include "theme/utils/logging.h"
+namespace bf = boost::filesystem;
+
namespace {
const char kThemeFilesPrefix[] = "/theme/files";
return loader::ThemeInfo(bundle_);
}
-void ThemeInfoBuilder::GenerateFileKey() {
+void ThemeInfoBuilder::GenerateFileKey(const std::string& root) {
+ for (bf::recursive_directory_iterator it(root);
+ it != bf::recursive_directory_iterator(); ++it) {
+ if (!bf::is_regular_file(it->path()))
+ continue;
+
+ if (!StartsWith(it->path().string(), root))
+ continue;
+
+ // root.size() -1 to remove trailing '/' charater
+ std::string filepath = it->path().string().substr(root.size() - 1);
+ std::string key = kThemeFilesPrefix + filepath;
+ bundle_.Add(key, it->path().string());
+ }
+
+ GenerateFileKeyWithoutExtension();
+}
+
+void ThemeInfoBuilder::GenerateFileKeyWithoutExtension() {
std::vector<tizen_base::Bundle::KeyInfo> keyinfos = bundle_.GetKeys();
for (const auto& keyinfo : keyinfos) {
std::string key = keyinfo.GetName();
continue;
std::string newkey = key.substr(0, dot_pos);
- LOG(DEBUG) << "Adding generated key: " << newkey;
bundle_.Add(newkey, bundle_.GetString(key));
}
}
ThemeInfoBuilder& PutStringArray(const std::string& key,
const std::vector<std::string>& value);
loader::ThemeInfo Build();
- void GenerateFileKey();
+ void GenerateFileKey(const std::string& root);
+ void GenerateFileKeyWithoutExtension();
private:
tizen_base::Bundle bundle_;
#include "theme_plugin/theme_parser.h"
+#include <pkgmgr-info.h>
#include <sys/types.h>
#include <fstream>
#include "theme/utils/logging.h"
#include "theme_plugin/theme_info_builder.h"
+namespace {
+
+std::string GetFileKeyRootPath(const char* pkgid) {
+ pkgmgrinfo_pkginfo_h handle;
+ int ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+ if (ret != PMINFO_R_OK)
+ return {};
+ char *root_path;
+ ret = pkgmgrinfo_pkginfo_get_root_path(handle, &root_path);
+ if (ret != PMINFO_R_OK) {
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ return {};
+ }
+ std::string path(root_path);
+ path += "/shared/res/";
+ pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ return path;
+}
+
+} // namespace
+
namespace ttm {
namespace plugin {
}
if (auto_file_key_gen_)
- builder.GenerateFileKey();
+ builder.GenerateFileKey(GetFileKeyRootPath(pkgid.c_str()));
return builder.Build();
}
},
"keyboard": {
"keypad_bg_color": "#050a28"
- },
- "files": {
- "shared/res/image1.png": "shared/res/image1.png",
- "shared/res/image2.svg": "shared/res/image2.svg"
}
}
}
#include <gtest/gtest.h>
+#include <string>
+#include <vector>
+
#include "theme/loader/theme_info.h"
#include "theme_plugin/theme_parser.h"
+#include "unit_tests/mock/gio_mock.h"
+#include "unit_tests/mock/pkgmgr_info_mock.h"
+#include "unit_tests/mock/test_fixture.h"
-#include <string>
-#include <vector>
+using ::testing::_;
+using ::testing::Return;
+using ::testing::SetArgPointee;
+
+class Mocks : public ::testing::NiceMock<GioMock>,
+ public ::testing::NiceMock<PkgmgrInfoMock> {};
-class ThemeParserTest : public testing::Test {
+class ThemeParserTest : public TestFixture {
public:
- virtual ~ThemeParserTest() {}
+ ThemeParserTest() : TestFixture(std::make_unique<Mocks>()) {}
virtual void SetUp() {
}
};
TEST_F(ThemeParserTest, Inflate) {
+ char root_path[] = "test_samples";
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_pkginfo_get_root_path(_, _)).
+ WillOnce(DoAll(
+ SetArgPointee<1>(const_cast<char*>(root_path)),
+ Return(PMINFO_R_OK)));
+
ttm::plugin::ThemeParser parser("test_samples/test_theme.json", true);
auto info = parser.Inflate("testid", "testpkgid", 5001, true);
EXPECT_EQ(info.GetId(), "testid");
"https://www.download.gogowatch/get");
EXPECT_EQ(info.GetStringArray("/theme/preview"),
std::vector<std::string>({"GOGO_Preview.png"}));
- EXPECT_EQ(info.GetString("/theme/files/shared/res/image1.png"),
- "shared/res/image1.png");
- EXPECT_EQ(info.GetString("/theme/files/shared/res/image1"),
- "shared/res/image1.png");
- EXPECT_EQ(info.GetString("/theme/files/shared/res/image2.svg"),
- "shared/res/image2.svg");
- EXPECT_EQ(info.GetString("/theme/files/shared/res/image2"),
- "shared/res/image2.svg");
+ EXPECT_EQ(info.GetString("/theme/files/test"),
+ "test_samples/shared/res/test");
+ EXPECT_EQ(info.GetString("/theme/files/picture"),
+ "test_samples/shared/res/picture.png");
}
TEST_F(ThemeParserTest, MultidimensionalArray) {