blob: ad4e3ce02b32b7aa331ed6ff03ed6cf58e4fea10 [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 Lesinskice5e56e2016-10-21 17:56:45 -070018
Adam Lesinskid0f116b2016-07-08 15:00:32 -070019#include "test/Test.h"
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080020
21namespace aapt {
22
23TEST(ResourceTypeTest, ParseResourceTypes) {
Adam Lesinskice5e56e2016-10-21 17:56:45 -070024 const ResourceType* type = ParseResourceType("anim");
Adam Lesinskicacb28f2016-10-19 12:18:14 -070025 ASSERT_NE(type, nullptr);
26 EXPECT_EQ(*type, ResourceType::kAnim);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080027
Adam Lesinskice5e56e2016-10-21 17:56:45 -070028 type = ParseResourceType("animator");
Adam Lesinskicacb28f2016-10-19 12:18:14 -070029 ASSERT_NE(type, nullptr);
30 EXPECT_EQ(*type, ResourceType::kAnimator);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080031
Adam Lesinskice5e56e2016-10-21 17:56:45 -070032 type = ParseResourceType("array");
Adam Lesinskicacb28f2016-10-19 12:18:14 -070033 ASSERT_NE(type, nullptr);
34 EXPECT_EQ(*type, ResourceType::kArray);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080035
Adam Lesinskice5e56e2016-10-21 17:56:45 -070036 type = ParseResourceType("attr");
Adam Lesinskicacb28f2016-10-19 12:18:14 -070037 ASSERT_NE(type, nullptr);
38 EXPECT_EQ(*type, ResourceType::kAttr);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080039
Adam Lesinskice5e56e2016-10-21 17:56:45 -070040 type = ParseResourceType("^attr-private");
Adam Lesinskicacb28f2016-10-19 12:18:14 -070041 ASSERT_NE(type, nullptr);
42 EXPECT_EQ(*type, ResourceType::kAttrPrivate);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080043
Adam Lesinskice5e56e2016-10-21 17:56:45 -070044 type = ParseResourceType("bool");
Adam Lesinskicacb28f2016-10-19 12:18:14 -070045 ASSERT_NE(type, nullptr);
46 EXPECT_EQ(*type, ResourceType::kBool);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080047
Adam Lesinskice5e56e2016-10-21 17:56:45 -070048 type = ParseResourceType("color");
Adam Lesinskicacb28f2016-10-19 12:18:14 -070049 ASSERT_NE(type, nullptr);
50 EXPECT_EQ(*type, ResourceType::kColor);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080051
Adam Lesinski86d67df2017-01-31 13:47:27 -080052 type = ParseResourceType("configVarying");
53 ASSERT_NE(type, nullptr);
54 EXPECT_EQ(*type, ResourceType::kConfigVarying);
55
Adam Lesinskice5e56e2016-10-21 17:56:45 -070056 type = ParseResourceType("dimen");
Adam Lesinskicacb28f2016-10-19 12:18:14 -070057 ASSERT_NE(type, nullptr);
58 EXPECT_EQ(*type, ResourceType::kDimen);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080059
Adam Lesinskice5e56e2016-10-21 17:56:45 -070060 type = ParseResourceType("drawable");
Adam Lesinskicacb28f2016-10-19 12:18:14 -070061 ASSERT_NE(type, nullptr);
62 EXPECT_EQ(*type, ResourceType::kDrawable);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080063
Adam Lesinskic0c36632016-10-19 18:37:53 -070064 type = ParseResourceType("font");
65 ASSERT_NE(type, nullptr);
66 EXPECT_EQ(*type, ResourceType::kFont);
67
Adam Lesinskice5e56e2016-10-21 17:56:45 -070068 type = ParseResourceType("fraction");
Adam Lesinskicacb28f2016-10-19 12:18:14 -070069 ASSERT_NE(type, nullptr);
70 EXPECT_EQ(*type, ResourceType::kFraction);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080071
Adam Lesinskice5e56e2016-10-21 17:56:45 -070072 type = ParseResourceType("id");
Adam Lesinskicacb28f2016-10-19 12:18:14 -070073 ASSERT_NE(type, nullptr);
74 EXPECT_EQ(*type, ResourceType::kId);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080075
Adam Lesinskice5e56e2016-10-21 17:56:45 -070076 type = ParseResourceType("integer");
Adam Lesinskicacb28f2016-10-19 12:18:14 -070077 ASSERT_NE(type, nullptr);
78 EXPECT_EQ(*type, ResourceType::kInteger);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080079
Adam Lesinskice5e56e2016-10-21 17:56:45 -070080 type = ParseResourceType("interpolator");
Adam Lesinskicacb28f2016-10-19 12:18:14 -070081 ASSERT_NE(type, nullptr);
82 EXPECT_EQ(*type, ResourceType::kInterpolator);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080083
Adam Lesinskice5e56e2016-10-21 17:56:45 -070084 type = ParseResourceType("layout");
Adam Lesinskicacb28f2016-10-19 12:18:14 -070085 ASSERT_NE(type, nullptr);
86 EXPECT_EQ(*type, ResourceType::kLayout);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080087
Adam Lesinskice5e56e2016-10-21 17:56:45 -070088 type = ParseResourceType("menu");
Adam Lesinskicacb28f2016-10-19 12:18:14 -070089 ASSERT_NE(type, nullptr);
90 EXPECT_EQ(*type, ResourceType::kMenu);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080091
Adam Lesinskice5e56e2016-10-21 17:56:45 -070092 type = ParseResourceType("mipmap");
Adam Lesinskicacb28f2016-10-19 12:18:14 -070093 ASSERT_NE(type, nullptr);
94 EXPECT_EQ(*type, ResourceType::kMipmap);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080095
Adam Lesinskice5e56e2016-10-21 17:56:45 -070096 type = ParseResourceType("plurals");
Adam Lesinskicacb28f2016-10-19 12:18:14 -070097 ASSERT_NE(type, nullptr);
98 EXPECT_EQ(*type, ResourceType::kPlurals);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080099
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700100 type = ParseResourceType("raw");
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700101 ASSERT_NE(type, nullptr);
102 EXPECT_EQ(*type, ResourceType::kRaw);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800103
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700104 type = ParseResourceType("string");
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700105 ASSERT_NE(type, nullptr);
106 EXPECT_EQ(*type, ResourceType::kString);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800107
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700108 type = ParseResourceType("style");
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700109 ASSERT_NE(type, nullptr);
110 EXPECT_EQ(*type, ResourceType::kStyle);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800111
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700112 type = ParseResourceType("transition");
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700113 ASSERT_NE(type, nullptr);
114 EXPECT_EQ(*type, ResourceType::kTransition);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800115
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700116 type = ParseResourceType("xml");
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700117 ASSERT_NE(type, nullptr);
118 EXPECT_EQ(*type, ResourceType::kXml);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800119
Adam Lesinskice5e56e2016-10-21 17:56:45 -0700120 type = ParseResourceType("blahaha");
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700121 EXPECT_EQ(type, nullptr);
Adam Lesinski6f6ceb72014-11-14 14:48:12 -0800122}
123
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700124} // namespace aapt