blob: b1b6013e9b7d00d9ef25a7ddde58e293280e8ee9 [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"
surmeh0149b9e102018-05-17 14:11:25 +01006#include <log/log.h>
7#include "../SystemPropertiesUtils.hpp"
8
Sadik Armagan9150bff2021-05-26 15:40:53 +01009#include <doctest/doctest.h>
surmeh0149b9e102018-05-17 14:11:25 +010010
Sadik Armagan9150bff2021-05-26 15:40:53 +010011TEST_SUITE("SystemProperiesTests")
12{
13TEST_CASE("SystemProperties")
surmeh0149b9e102018-05-17 14:11:25 +010014{
15 // Test default value
16 {
17 auto p = __system_property_find("thisDoesNotExist");
Sadik Armagan9150bff2021-05-26 15:40:53 +010018 CHECK((p == nullptr));
surmeh0149b9e102018-05-17 14:11:25 +010019
20 int defaultValue = ParseSystemProperty("thisDoesNotExist", -4);
Sadik Armagan9150bff2021-05-26 15:40:53 +010021 CHECK((defaultValue == -4));
surmeh0149b9e102018-05-17 14:11:25 +010022 }
23
24 // Test default value from bad data type
25 {
26 __system_property_set("thisIsNotFloat", "notfloat");
27 float defaultValue = ParseSystemProperty("thisIsNotFloat", 0.1f);
Sadik Armagan9150bff2021-05-26 15:40:53 +010028 CHECK((defaultValue == 0.1f));
surmeh0149b9e102018-05-17 14:11:25 +010029 }
30
31 // Test fetching bool values
32 {
33 __system_property_set("myTestBool", "1");
34 bool b = ParseSystemProperty("myTestBool", false);
Sadik Armagan9150bff2021-05-26 15:40:53 +010035 CHECK((b == true));
surmeh0149b9e102018-05-17 14:11:25 +010036 }
37 {
38 __system_property_set("myTestBool", "0");
39 bool b = ParseSystemProperty("myTestBool", true);
Sadik Armagan9150bff2021-05-26 15:40:53 +010040 CHECK((b == false));
surmeh0149b9e102018-05-17 14:11:25 +010041 }
42
43 // Test fetching int
44 {
45 __system_property_set("myTestInt", "567");
46 int i = ParseSystemProperty("myTestInt", 890);
Sadik Armagan9150bff2021-05-26 15:40:53 +010047 CHECK((i==567));
surmeh0149b9e102018-05-17 14:11:25 +010048 }
49
50 // Test fetching float
51 {
52 __system_property_set("myTestFloat", "1.2f");
53 float f = ParseSystemProperty("myTestFloat", 3.4f);
Sadik Armagan9150bff2021-05-26 15:40:53 +010054 CHECK((f==1.2f));
surmeh0149b9e102018-05-17 14:11:25 +010055 }
56}
57
Sadik Armagan9150bff2021-05-26 15:40:53 +010058}