Loading cmds/bootanimation/Android.mk +2 −0 Original line number Diff line number Diff line Loading @@ -94,3 +94,5 @@ LOCAL_32_BIT_ONLY := true endif include ${BUILD_SHARED_LIBRARY} include $(call all-makefiles-under,$(LOCAL_PATH)) cmds/bootanimation/iot/Android.mk 0 → 100644 +38 −0 Original line number Diff line number Diff line # Copyright (C) 2018 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # LOCAL_PATH:= $(call my-dir) ifeq ($(PRODUCT_IOT),true) # libbootanimation_iot_test # =========================================================== include $(CLEAR_VARS) LOCAL_MODULE := libbootanimation_iot_test LOCAL_CFLAGS := -Wall -Werror -Wunused -Wunreachable-code LOCAL_SHARED_LIBRARIES := \ libandroidthings \ libbase \ libchrome \ liblog \ LOCAL_SRC_FILES := \ BootParameters.cpp \ BootParameters_test.cpp \ include $(BUILD_NATIVE_TEST) endif # PRODUCT_IOT cmds/bootanimation/iot/BootParameters.cpp +5 −3 Original line number Diff line number Diff line Loading @@ -20,8 +20,6 @@ #include <fcntl.h> #include <string> #include <android-base/file.h> #include <base/json/json_parser.h> #include <base/json/json_reader.h> Loading Loading @@ -98,7 +96,11 @@ void BootParameters::loadParameters() { return; } std::unique_ptr<Value> json = JSONReader::Read(contents); loadParameters(contents); } void BootParameters::loadParameters(const std::string& raw_json) { std::unique_ptr<Value> json = JSONReader::Read(raw_json); if (json.get() == nullptr) { return; } Loading cmds/bootanimation/iot/BootParameters.h +3 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #define _BOOTANIMATION_BOOT_PARAMETERS_H_ #include <list> #include <string> #include <vector> #include <base/json/json_value_converter.h> Loading @@ -43,6 +44,8 @@ public: // Returns the additional boot parameters that were set on reboot. const std::vector<ABootActionParameter>& getParameters() const { return mParameters; } // Exposed for testing. Updates the parameters with new JSON values. void loadParameters(const std::string& raw_json); private: // Raw boot saved_parameters loaded from .json. struct SavedBootParameters { Loading cmds/bootanimation/iot/BootParameters_test.cpp 0 → 100644 +88 −0 Original line number Diff line number Diff line /* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "BootParameters.h" #include <gtest/gtest.h> namespace android { namespace { TEST(BootParametersTest, TestParseValidParameters) { BootParameters boot_parameters = BootParameters(); boot_parameters.loadParameters(R"( { "brightness":200, "volume":100, "param_names":["key1","key2"], "param_values":["value1","value2"] } )"); EXPECT_TRUE(boot_parameters.hasBrightness()); EXPECT_TRUE(boot_parameters.hasVolume()); EXPECT_FLOAT_EQ(0.2f, boot_parameters.getBrightness()); EXPECT_FLOAT_EQ(0.1f, boot_parameters.getVolume()); auto parameters = boot_parameters.getParameters(); ASSERT_EQ(2u, parameters.size()); ASSERT_STREQ(parameters[0].key, "key1"); ASSERT_STREQ(parameters[0].value, "value1"); ASSERT_STREQ(parameters[1].key, "key2"); ASSERT_STREQ(parameters[1].value, "value2"); } TEST(BootParametersTest, TestMismatchedParameters) { BootParameters boot_parameters = BootParameters(); boot_parameters.loadParameters(R"( { "brightness":500, "volume":500, "param_names":["key1","key2"], "param_values":["value1"] } )"); EXPECT_TRUE(boot_parameters.hasBrightness()); EXPECT_TRUE(boot_parameters.hasVolume()); EXPECT_FLOAT_EQ(0.5f, boot_parameters.getBrightness()); EXPECT_FLOAT_EQ(0.5f, boot_parameters.getVolume()); auto parameters = boot_parameters.getParameters(); ASSERT_EQ(0u, parameters.size()); } TEST(BootParametersTest, TestMissingParameters) { BootParameters boot_parameters = BootParameters(); boot_parameters.loadParameters(R"( { "brightness":500 } )"); EXPECT_TRUE(boot_parameters.hasBrightness()); EXPECT_FALSE(boot_parameters.hasVolume()); EXPECT_FLOAT_EQ(0.5f, boot_parameters.getBrightness()); EXPECT_FLOAT_EQ(-1.0f, boot_parameters.getVolume()); auto parameters = boot_parameters.getParameters(); ASSERT_EQ(0u, parameters.size()); } } // namespace } // namespace android Loading
cmds/bootanimation/Android.mk +2 −0 Original line number Diff line number Diff line Loading @@ -94,3 +94,5 @@ LOCAL_32_BIT_ONLY := true endif include ${BUILD_SHARED_LIBRARY} include $(call all-makefiles-under,$(LOCAL_PATH))
cmds/bootanimation/iot/Android.mk 0 → 100644 +38 −0 Original line number Diff line number Diff line # Copyright (C) 2018 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # LOCAL_PATH:= $(call my-dir) ifeq ($(PRODUCT_IOT),true) # libbootanimation_iot_test # =========================================================== include $(CLEAR_VARS) LOCAL_MODULE := libbootanimation_iot_test LOCAL_CFLAGS := -Wall -Werror -Wunused -Wunreachable-code LOCAL_SHARED_LIBRARIES := \ libandroidthings \ libbase \ libchrome \ liblog \ LOCAL_SRC_FILES := \ BootParameters.cpp \ BootParameters_test.cpp \ include $(BUILD_NATIVE_TEST) endif # PRODUCT_IOT
cmds/bootanimation/iot/BootParameters.cpp +5 −3 Original line number Diff line number Diff line Loading @@ -20,8 +20,6 @@ #include <fcntl.h> #include <string> #include <android-base/file.h> #include <base/json/json_parser.h> #include <base/json/json_reader.h> Loading Loading @@ -98,7 +96,11 @@ void BootParameters::loadParameters() { return; } std::unique_ptr<Value> json = JSONReader::Read(contents); loadParameters(contents); } void BootParameters::loadParameters(const std::string& raw_json) { std::unique_ptr<Value> json = JSONReader::Read(raw_json); if (json.get() == nullptr) { return; } Loading
cmds/bootanimation/iot/BootParameters.h +3 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #define _BOOTANIMATION_BOOT_PARAMETERS_H_ #include <list> #include <string> #include <vector> #include <base/json/json_value_converter.h> Loading @@ -43,6 +44,8 @@ public: // Returns the additional boot parameters that were set on reboot. const std::vector<ABootActionParameter>& getParameters() const { return mParameters; } // Exposed for testing. Updates the parameters with new JSON values. void loadParameters(const std::string& raw_json); private: // Raw boot saved_parameters loaded from .json. struct SavedBootParameters { Loading
cmds/bootanimation/iot/BootParameters_test.cpp 0 → 100644 +88 −0 Original line number Diff line number Diff line /* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "BootParameters.h" #include <gtest/gtest.h> namespace android { namespace { TEST(BootParametersTest, TestParseValidParameters) { BootParameters boot_parameters = BootParameters(); boot_parameters.loadParameters(R"( { "brightness":200, "volume":100, "param_names":["key1","key2"], "param_values":["value1","value2"] } )"); EXPECT_TRUE(boot_parameters.hasBrightness()); EXPECT_TRUE(boot_parameters.hasVolume()); EXPECT_FLOAT_EQ(0.2f, boot_parameters.getBrightness()); EXPECT_FLOAT_EQ(0.1f, boot_parameters.getVolume()); auto parameters = boot_parameters.getParameters(); ASSERT_EQ(2u, parameters.size()); ASSERT_STREQ(parameters[0].key, "key1"); ASSERT_STREQ(parameters[0].value, "value1"); ASSERT_STREQ(parameters[1].key, "key2"); ASSERT_STREQ(parameters[1].value, "value2"); } TEST(BootParametersTest, TestMismatchedParameters) { BootParameters boot_parameters = BootParameters(); boot_parameters.loadParameters(R"( { "brightness":500, "volume":500, "param_names":["key1","key2"], "param_values":["value1"] } )"); EXPECT_TRUE(boot_parameters.hasBrightness()); EXPECT_TRUE(boot_parameters.hasVolume()); EXPECT_FLOAT_EQ(0.5f, boot_parameters.getBrightness()); EXPECT_FLOAT_EQ(0.5f, boot_parameters.getVolume()); auto parameters = boot_parameters.getParameters(); ASSERT_EQ(0u, parameters.size()); } TEST(BootParametersTest, TestMissingParameters) { BootParameters boot_parameters = BootParameters(); boot_parameters.loadParameters(R"( { "brightness":500 } )"); EXPECT_TRUE(boot_parameters.hasBrightness()); EXPECT_FALSE(boot_parameters.hasVolume()); EXPECT_FLOAT_EQ(0.5f, boot_parameters.getBrightness()); EXPECT_FLOAT_EQ(-1.0f, boot_parameters.getVolume()); auto parameters = boot_parameters.getParameters(); ASSERT_EQ(0u, parameters.size()); } } // namespace } // namespace android