1 /*
2  * Copyright (C) 2017 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 "androidfw/ResourceUtils.h"
18 
19 #include "TestHelpers.h"
20 
21 namespace android {
22 
TEST(ResourceUtilsTest,ExtractResourceName)23 TEST(ResourceUtilsTest, ExtractResourceName) {
24   StringPiece package, type, entry;
25   ASSERT_TRUE(ExtractResourceName("android:string/foo", &package, &type, &entry));
26   EXPECT_EQ("android", package);
27   EXPECT_EQ("string", type);
28   EXPECT_EQ("foo", entry);
29 
30   ASSERT_TRUE(ExtractResourceName("@android:string/foo", &package, &type, &entry));
31   EXPECT_EQ("android", package);
32   EXPECT_EQ("string", type);
33   EXPECT_EQ("foo", entry);
34 
35   ASSERT_TRUE(ExtractResourceName("string/foo", &package, &type, &entry));
36   EXPECT_EQ("", package);
37   EXPECT_EQ("string", type);
38   EXPECT_EQ("foo", entry);
39 
40   ASSERT_TRUE(ExtractResourceName("@string/foo", &package, &type, &entry));
41   EXPECT_EQ("", package);
42   EXPECT_EQ("string", type);
43   EXPECT_EQ("foo", entry);
44 
45   ASSERT_TRUE(ExtractResourceName("foo", &package, &type, &entry));
46   EXPECT_EQ("", package);
47   EXPECT_EQ("", type);
48   EXPECT_EQ("foo", entry);
49 
50   ASSERT_TRUE(ExtractResourceName("@foo", &package, &type, &entry));
51   EXPECT_EQ("", package);
52   EXPECT_EQ("", type);
53   EXPECT_EQ("foo", entry);
54 
55   ASSERT_TRUE(ExtractResourceName("android:foo", &package, &type, &entry));
56   EXPECT_EQ("android", package);
57   EXPECT_EQ("", type);
58   EXPECT_EQ("foo", entry);
59 
60 //  ASSERT_TRUE(ExtractResourceName("@android:foo", &package, &type, &entry));
61 //  EXPECT_EQ("android", package);
62 //  EXPECT_EQ("", type);
63 //  EXPECT_EQ("foo", entry);
64 
65   EXPECT_FALSE(ExtractResourceName(":string/foo", &package, &type, &entry));
66 
67   EXPECT_FALSE(ExtractResourceName("@:string/foo", &package, &type, &entry));
68 
69   EXPECT_FALSE(ExtractResourceName("/foo", &package, &type, &entry));
70 
71   EXPECT_FALSE(ExtractResourceName("@/foo", &package, &type, &entry));
72 }
73 
74 }  // namespace android
75