• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "gtest/gtest.h"
18 
19 #include <dlfcn.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <sys/system_properties.h>
23 
TEST(SystemProperties,Get)24 TEST(SystemProperties, Get) {
25   char value[PROP_VALUE_MAX];
26   ASSERT_GT(__system_property_get("ro.build.version.sdk", value), 0);
27   EXPECT_GE(atoi(value), 19);
28 }
29 
ForEachCallback(const prop_info * pi,void * cookie)30 void ForEachCallback(const prop_info* pi, void* cookie) {
31   char name[PROP_NAME_MAX];
32   char value[PROP_VALUE_MAX];
33   __system_property_read(pi, name, value);
34   if (strcmp(name, "ro.build.version.sdk") == 0) {
35     *reinterpret_cast<bool*>(cookie) = true;
36   }
37 }
38 
TEST(SystemProperties,ForEach)39 TEST(SystemProperties, ForEach) {
40   bool has_build_version_sdk = false;
41   ASSERT_EQ(__system_property_foreach(ForEachCallback, &has_build_version_sdk), 0);
42   ASSERT_TRUE(has_build_version_sdk);
43 }
44