-
Notifications
You must be signed in to change notification settings - Fork 17
Unit tests for the settings channel #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
fee84ca
fd3997d
295e577
dbeaa9f
2d187dc
22c726c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,40 @@ | ||||||||
// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved. | ||||||||
// Use of this source code is governed by a BSD-style license that can be | ||||||||
// found in the LICENSE file. | ||||||||
|
||||||||
#include "settings_channel.h" | ||||||||
|
||||||||
#include <chrono> | ||||||||
#include <ctime> | ||||||||
Comment on lines
+7
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
||||||||
namespace flutter { | ||||||||
|
||||||||
void SettingsChannel::Init() { | ||||||||
std::locale::global(std::locale("")); | ||||||||
bwikbs marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
} | ||||||||
|
||||||||
void SettingsChannel::Dispose() {} | ||||||||
|
||||||||
bool SettingsChannel::GetSettingValueOf24Format(bool* value) { | ||||||||
// This is a temporary implementation because I didn't know how to properly implement it. | ||||||||
// I believe someone will replace it with a better implementation. | ||||||||
// This function operates normally only in the following locale. | ||||||||
// en_US.UTF-8, ko_KR.UTF-8 | ||||||||
swift-kim marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
char buf[64]; | ||||||||
std::time_t current = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); | ||||||||
if(!strftime(buf, sizeof(buf), "%c", std::localtime(¤t))){ | ||||||||
return false; | ||||||||
} | ||||||||
std::string current_local_time(buf); | ||||||||
if ((current_local_time.find("AM")!=std::string::npos) | ||||||||
|| (current_local_time.find("PM")!=std::string::npos) | ||||||||
|| (current_local_time.find("오전")!=std::string::npos) | ||||||||
|| (current_local_time.find("오후")!=std::string::npos) | ||||||||
){ | ||||||||
*value = true; | ||||||||
} | ||||||||
*value = false; | ||||||||
return true; | ||||||||
} | ||||||||
|
||||||||
} // namespace flutter |
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,35 @@ | ||||||||||||
// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved. | ||||||||||||
// Use of this source code is governed by a BSD-style license that can be | ||||||||||||
// found in the LICENSE file. | ||||||||||||
|
||||||||||||
#include <system/system_settings.h> | ||||||||||||
#include "settings_channel.h" | ||||||||||||
Comment on lines
+5
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
|
||||||||||||
namespace flutter { | ||||||||||||
|
||||||||||||
static void OnSettingsChangedCallback(system_settings_key_e key, | ||||||||||||
void* user_data) { | ||||||||||||
auto settings_channel = reinterpret_cast<SettingsChannel*>(user_data); | ||||||||||||
settings_channel->SendSettingsEvent(); | ||||||||||||
} | ||||||||||||
|
||||||||||||
void SettingsChannel::Init() { | ||||||||||||
system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, | ||||||||||||
OnSettingsChangedCallback, this); | ||||||||||||
} | ||||||||||||
|
||||||||||||
void SettingsChannel::Dispose() { | ||||||||||||
system_settings_unset_changed_cb( | ||||||||||||
SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR); | ||||||||||||
} | ||||||||||||
|
||||||||||||
bool SettingsChannel::GetSettingValueOf24Format(bool* value) { | ||||||||||||
if (system_settings_get_value_bool( | ||||||||||||
SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, value) == | ||||||||||||
SYSTEM_SETTINGS_ERROR_NONE) { | ||||||||||||
return true; | ||||||||||||
} | ||||||||||||
return false; | ||||||||||||
} | ||||||||||||
|
||||||||||||
} // namespace flutter |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,7 +2,11 @@ | |||||||||||||||
// Use of this source code is governed by a BSD-style license that can be | ||||||||||||||||
// found in the LICENSE file. | ||||||||||||||||
|
||||||||||||||||
#include <filesystem> | ||||||||||||||||
bwikbs marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
|
||||||||||||||||
#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h" | ||||||||||||||||
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h" | ||||||||||||||||
#include "flutter/shell/platform/tizen/testing/engine_modifier.h" | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
#include "gtest/gtest.h" | ||||||||||||||||
|
||||||||||||||||
namespace flutter { | ||||||||||||||||
|
@@ -18,9 +22,9 @@ class FlutterTizenEngineTest : public ::testing::Test { | |||||||||||||||
protected: | ||||||||||||||||
void SetUp() { | ||||||||||||||||
FlutterDesktopEngineProperties engine_prop = {}; | ||||||||||||||||
engine_prop.assets_path = "foo/flutter_assets"; | ||||||||||||||||
engine_prop.icu_data_path = "foo/icudtl.dat"; | ||||||||||||||||
engine_prop.aot_library_path = "foo/libapp.so"; | ||||||||||||||||
engine_prop.assets_path = "/foo/flutter_assets"; | ||||||||||||||||
engine_prop.icu_data_path = "/foo/icudtl.dat"; | ||||||||||||||||
engine_prop.aot_library_path = "/foo/libapp.so"; | ||||||||||||||||
|
||||||||||||||||
FlutterProjectBundle project(engine_prop); | ||||||||||||||||
auto engine = std::make_unique<FlutterTizenEngine>(project); | ||||||||||||||||
|
@@ -81,5 +85,64 @@ TEST_F(FlutterTizenEngineTestHeaded, GetTextureRegistrar) { | |||||||||||||||
EXPECT_TRUE(engine_->GetTextureRegistrar() != nullptr); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
TEST_F(FlutterTizenEngineTest, RunDoesExpectedInitialization) { | ||||||||||||||||
EngineModifier modifier(engine_); | ||||||||||||||||
bool run_called = false; | ||||||||||||||||
modifier.embedder_api().Run = MOCK_ENGINE_PROC( | ||||||||||||||||
Run, ([&run_called, engine_instance = engine_]( | ||||||||||||||||
size_t version, const FlutterRendererConfig* config, | ||||||||||||||||
const FlutterProjectArgs* args, void* user_data, | ||||||||||||||||
FLUTTER_API_SYMBOL(FlutterEngine) * engine_out) { | ||||||||||||||||
std::string current_path = std::filesystem::current_path().string(); | ||||||||||||||||
bwikbs marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
run_called = true; | ||||||||||||||||
*engine_out = reinterpret_cast<FLUTTER_API_SYMBOL(FlutterEngine)>(1); | ||||||||||||||||
|
||||||||||||||||
EXPECT_EQ(version, (size_t)FLUTTER_ENGINE_VERSION); | ||||||||||||||||
EXPECT_NE(config, nullptr); | ||||||||||||||||
EXPECT_EQ(user_data, engine_instance); | ||||||||||||||||
|
||||||||||||||||
EXPECT_STREQ(args->assets_path, "/foo/flutter_assets"); | ||||||||||||||||
EXPECT_STREQ(args->icu_data_path, "/foo/icudtl.dat"); | ||||||||||||||||
EXPECT_EQ(args->dart_entrypoint_argc, 0); | ||||||||||||||||
EXPECT_NE(args->platform_message_callback, nullptr); | ||||||||||||||||
EXPECT_NE(args->custom_task_runners, nullptr); | ||||||||||||||||
EXPECT_EQ(args->custom_dart_entrypoint, nullptr); | ||||||||||||||||
|
||||||||||||||||
return kSuccess; | ||||||||||||||||
})); | ||||||||||||||||
|
||||||||||||||||
// It should send locale info. | ||||||||||||||||
bool update_locales_called = false; | ||||||||||||||||
modifier.embedder_api().UpdateLocales = MOCK_ENGINE_PROC( | ||||||||||||||||
UpdateLocales, | ||||||||||||||||
([&update_locales_called](auto engine, const FlutterLocale** locales, | ||||||||||||||||
size_t locales_count) { | ||||||||||||||||
update_locales_called = true; | ||||||||||||||||
EXPECT_GT(locales_count, (size_t)0); | ||||||||||||||||
EXPECT_NE(locales, nullptr); | ||||||||||||||||
|
||||||||||||||||
return kSuccess; | ||||||||||||||||
})); | ||||||||||||||||
|
||||||||||||||||
// And it should send initial settings info. | ||||||||||||||||
bool settings_message_sent = false; | ||||||||||||||||
modifier.embedder_api().SendPlatformMessage = MOCK_ENGINE_PROC( | ||||||||||||||||
SendPlatformMessage, | ||||||||||||||||
([&settings_message_sent](auto engine, auto message) { | ||||||||||||||||
if (std::string(message->channel) == std::string("flutter/settings")) { | ||||||||||||||||
settings_message_sent = true; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
return kSuccess; | ||||||||||||||||
})); | ||||||||||||||||
|
||||||||||||||||
engine_->RunEngine(); | ||||||||||||||||
|
||||||||||||||||
EXPECT_TRUE(run_called); | ||||||||||||||||
EXPECT_TRUE(update_locales_called); | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, this test does not pass. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will pass at #147. For the next PR, only TC was added intentionally. |
||||||||||||||||
EXPECT_TRUE(settings_message_sent); | ||||||||||||||||
|
||||||||||||||||
modifier.embedder_api().Shutdown = [](auto engine) { return kSuccess; }; | ||||||||||||||||
} | ||||||||||||||||
bwikbs marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
} // namespace testing | ||||||||||||||||
} // namespace flutter |
Uh oh!
There was an error while loading. Please reload this page.