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