blob: 4b6b122f984e2fa3ec82f0c39ae4824e36bb5d92 [file] [log] [blame]
Adam Lesinski6f6ceb72014-11-14 14:48:12 -08001/*
2 * Copyright (C) 2015 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
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080017#include "Resource.h"
Adam Lesinskid0f116b2016-07-08 15:00:32 -070018#include "test/Test.h"
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080019
20namespace aapt {
21
22TEST(ResourceTypeTest, ParseResourceTypes) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070023 const ResourceType* type = parseResourceType("anim");
24 ASSERT_NE(type, nullptr);
25 EXPECT_EQ(*type, ResourceType::kAnim);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080026
Adam Lesinskicacb28f2016-10-19 12:18:14 -070027 type = parseResourceType("animator");
28 ASSERT_NE(type, nullptr);
29 EXPECT_EQ(*type, ResourceType::kAnimator);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080030
Adam Lesinskicacb28f2016-10-19 12:18:14 -070031 type = parseResourceType("array");
32 ASSERT_NE(type, nullptr);
33 EXPECT_EQ(*type, ResourceType::kArray);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080034
Adam Lesinskicacb28f2016-10-19 12:18:14 -070035 type = parseResourceType("attr");
36 ASSERT_NE(type, nullptr);
37 EXPECT_EQ(*type, ResourceType::kAttr);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080038
Adam Lesinskicacb28f2016-10-19 12:18:14 -070039 type = parseResourceType("^attr-private");
40 ASSERT_NE(type, nullptr);
41 EXPECT_EQ(*type, ResourceType::kAttrPrivate);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080042
Adam Lesinskicacb28f2016-10-19 12:18:14 -070043 type = parseResourceType("bool");
44 ASSERT_NE(type, nullptr);
45 EXPECT_EQ(*type, ResourceType::kBool);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080046
Adam Lesinskicacb28f2016-10-19 12:18:14 -070047 type = parseResourceType("color");
48 ASSERT_NE(type, nullptr);
49 EXPECT_EQ(*type, ResourceType::kColor);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080050
Adam Lesinskicacb28f2016-10-19 12:18:14 -070051 type = parseResourceType("dimen");
52 ASSERT_NE(type, nullptr);
53 EXPECT_EQ(*type, ResourceType::kDimen);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080054
Adam Lesinskicacb28f2016-10-19 12:18:14 -070055 type = parseResourceType("drawable");
56 ASSERT_NE(type, nullptr);
57 EXPECT_EQ(*type, ResourceType::kDrawable);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080058
Adam Lesinskicacb28f2016-10-19 12:18:14 -070059 type = parseResourceType("fraction");
60 ASSERT_NE(type, nullptr);
61 EXPECT_EQ(*type, ResourceType::kFraction);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080062
Adam Lesinskicacb28f2016-10-19 12:18:14 -070063 type = parseResourceType("id");
64 ASSERT_NE(type, nullptr);
65 EXPECT_EQ(*type, ResourceType::kId);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080066
Adam Lesinskicacb28f2016-10-19 12:18:14 -070067 type = parseResourceType("integer");
68 ASSERT_NE(type, nullptr);
69 EXPECT_EQ(*type, ResourceType::kInteger);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080070
Adam Lesinskicacb28f2016-10-19 12:18:14 -070071 type = parseResourceType("interpolator");
72 ASSERT_NE(type, nullptr);
73 EXPECT_EQ(*type, ResourceType::kInterpolator);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080074
Adam Lesinskicacb28f2016-10-19 12:18:14 -070075 type = parseResourceType("layout");
76 ASSERT_NE(type, nullptr);
77 EXPECT_EQ(*type, ResourceType::kLayout);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080078
Adam Lesinskicacb28f2016-10-19 12:18:14 -070079 type = parseResourceType("menu");
80 ASSERT_NE(type, nullptr);
81 EXPECT_EQ(*type, ResourceType::kMenu);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080082
Adam Lesinskicacb28f2016-10-19 12:18:14 -070083 type = parseResourceType("mipmap");
84 ASSERT_NE(type, nullptr);
85 EXPECT_EQ(*type, ResourceType::kMipmap);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080086
Adam Lesinskicacb28f2016-10-19 12:18:14 -070087 type = parseResourceType("plurals");
88 ASSERT_NE(type, nullptr);
89 EXPECT_EQ(*type, ResourceType::kPlurals);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080090
Adam Lesinskicacb28f2016-10-19 12:18:14 -070091 type = parseResourceType("raw");
92 ASSERT_NE(type, nullptr);
93 EXPECT_EQ(*type, ResourceType::kRaw);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080094
Adam Lesinskicacb28f2016-10-19 12:18:14 -070095 type = parseResourceType("string");
96 ASSERT_NE(type, nullptr);
97 EXPECT_EQ(*type, ResourceType::kString);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080098
Adam Lesinskicacb28f2016-10-19 12:18:14 -070099 type = parseResourceType("style");
100 ASSERT_NE(type, nullptr);
101 EXPECT_EQ(*type, ResourceType::kStyle);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800102
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700103 type = parseResourceType("transition");
104 ASSERT_NE(type, nullptr);
105 EXPECT_EQ(*type, ResourceType::kTransition);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800106
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700107 type = parseResourceType("xml");
108 ASSERT_NE(type, nullptr);
109 EXPECT_EQ(*type, ResourceType::kXml);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800110
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700111 type = parseResourceType("blahaha");
112 EXPECT_EQ(type, nullptr);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800113}
114
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700115} // namespace aapt