1 // 2 // Copyright © 2017 Arm Ltd and Contributors. All rights reserved. 3 // SPDX-License-Identifier: MIT 4 // 5 6 #include "DriverTestHelpers.hpp" 7 #include <log/log.h> 8 #include <SystemPropertiesUtils.hpp> 9 10 DOCTEST_TEST_SUITE("SystemProperiesTests") 11 { 12 13 DOCTEST_TEST_CASE("SystemProperties") 14 { 15 // Test default value 16 { 17 auto p = __system_property_find("thisDoesNotExist"); 18 DOCTEST_CHECK((p == nullptr)); 19 20 int defaultValue = ParseSystemProperty("thisDoesNotExist", -4); 21 DOCTEST_CHECK((defaultValue == -4)); 22 } 23 24 // Test default value from bad data type 25 { 26 __system_property_set("thisIsNotFloat", "notfloat"); 27 float defaultValue = ParseSystemProperty("thisIsNotFloat", 0.1f); 28 DOCTEST_CHECK((defaultValue == 0.1f)); 29 } 30 31 // Test fetching bool values 32 { 33 __system_property_set("myTestBool", "1"); 34 bool b = ParseSystemProperty("myTestBool", false); 35 DOCTEST_CHECK((b == true)); 36 } 37 { 38 __system_property_set("myTestBool", "0"); 39 bool b = ParseSystemProperty("myTestBool", true); 40 DOCTEST_CHECK((b == false)); 41 } 42 43 // Test fetching int 44 { 45 __system_property_set("myTestInt", "567"); 46 int i = ParseSystemProperty("myTestInt", 890); 47 DOCTEST_CHECK((i==567)); 48 } 49 50 // Test fetching float 51 { 52 __system_property_set("myTestFloat", "1.2f"); 53 float f = ParseSystemProperty("myTestFloat", 3.4f); 54 DOCTEST_CHECK((f==1.2f)); 55 } 56 } 57 58 } 59