aboutsummaryrefslogtreecommitdiff
path: root/test/SystemProperties.cpp
blob: ef952964f7dc160c8a5a8fe0e4256dce152b6a1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//
// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include "DriverTestHelpers.hpp"
#include <log/log.h>
#include <SystemPropertiesUtils.hpp>

DOCTEST_TEST_SUITE("SystemProperiesTests")
{

DOCTEST_TEST_CASE("SystemProperties")
{
    // Test default value
    {
        auto p = __system_property_find("thisDoesNotExist");
        DOCTEST_CHECK((p == nullptr));

        int defaultValue = ParseSystemProperty("thisDoesNotExist", -4);
        DOCTEST_CHECK((defaultValue == -4));
    }

    //  Test default value from bad data type
    {
        __system_property_set("thisIsNotFloat", "notfloat");
        float defaultValue = ParseSystemProperty("thisIsNotFloat", 0.1f);
        DOCTEST_CHECK((defaultValue == 0.1f));
    }

    // Test fetching bool values
    {
        __system_property_set("myTestBool", "1");
        bool b = ParseSystemProperty("myTestBool", false);
        DOCTEST_CHECK((b == true));
    }
    {
        __system_property_set("myTestBool", "0");
        bool b = ParseSystemProperty("myTestBool", true);
        DOCTEST_CHECK((b == false));
    }

    // Test fetching int
    {
        __system_property_set("myTestInt", "567");
        int i = ParseSystemProperty("myTestInt", 890);
        DOCTEST_CHECK((i==567));
    }

    // Test fetching float
    {
        __system_property_set("myTestFloat", "1.2f");
        float f = ParseSystemProperty("myTestFloat", 3.4f);
        DOCTEST_CHECK((f==1.2f));
    }
}

}