blob: 098a7a5598bb0708c4c0210dfeac900b10c78571 [file] [log] [blame]
Christopher Wiley4582ecb2015-09-25 13:27:45 -07001/*
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
17#include <memory>
18
19#include <gtest/gtest.h>
20
21#include "aidl_language.h"
22#include "type_java.h"
23
24using std::unique_ptr;
25
26namespace android {
27namespace aidl {
Christopher Wileydb154a52015-09-28 16:32:25 -070028namespace java {
Christopher Wiley4582ecb2015-09-25 13:27:45 -070029
30class JavaTypeNamespaceTest : public ::testing::Test {
31 protected:
Christopher Wiley56799522015-10-31 10:17:04 -070032 void SetUp() override {
33 types_.Init();
34 }
Christopher Wiley4582ecb2015-09-25 13:27:45 -070035 JavaTypeNamespace types_;
36};
37
38TEST_F(JavaTypeNamespaceTest, HasSomeBasicTypes) {
Christopher Wiley9ab06232016-01-27 14:55:18 -080039 EXPECT_TRUE(types_.HasTypeByCanonicalName("void"));
40 EXPECT_TRUE(types_.HasTypeByCanonicalName("int"));
41 EXPECT_TRUE(types_.HasTypeByCanonicalName("java.lang.String"));
Christopher Wiley4582ecb2015-09-25 13:27:45 -070042}
43
44TEST_F(JavaTypeNamespaceTest, ContainerTypeCreation) {
45 // We start with no knowledge of parcelables or lists of them.
Christopher Wiley9ab06232016-01-27 14:55:18 -080046 EXPECT_FALSE(types_.HasTypeByCanonicalName("Foo"));
47 EXPECT_FALSE(types_.HasTypeByCanonicalName("java.util.List<a.goog.Foo>"));
Steven Moreland02e012e2018-08-02 14:58:10 -070048 unique_ptr<AidlParcelable> parcelable(new AidlParcelable(
Jiyong Parka6605ab2018-11-11 14:30:21 +090049 AIDL_LOCATION_HERE, new AidlQualifiedName(AIDL_LOCATION_HERE, "Foo", ""), {"a", "goog"}, ""));
Christopher Wiley4582ecb2015-09-25 13:27:45 -070050 // Add the parcelable type we care about.
Casey Dahlinc1f39b42015-11-24 10:34:34 -080051 EXPECT_TRUE(types_.AddParcelableType(*parcelable.get(), __FILE__));
Christopher Wiley4582ecb2015-09-25 13:27:45 -070052 // Now we can find the parcelable type, but not the List of them.
Christopher Wiley9ab06232016-01-27 14:55:18 -080053 EXPECT_TRUE(types_.HasTypeByCanonicalName("a.goog.Foo"));
54 EXPECT_FALSE(types_.HasTypeByCanonicalName("java.util.List<a.goog.Foo>"));
Christopher Wiley4582ecb2015-09-25 13:27:45 -070055 // But after we add the list explicitly...
Jiyong Parkd59a10d2018-07-18 11:12:55 +090056 std::vector<std::unique_ptr<AidlTypeSpecifier>>* type_args =
57 new std::vector<std::unique_ptr<AidlTypeSpecifier>>();
Steven Moreland02e012e2018-08-02 14:58:10 -070058 type_args->emplace_back(new AidlTypeSpecifier(AIDL_LOCATION_HERE, "Foo", false, nullptr, ""));
59 AidlTypeSpecifier container_type(AIDL_LOCATION_HERE, "List", false, type_args, "");
Christopher Wiley934a82d2016-01-27 13:02:24 -080060 EXPECT_TRUE(types_.MaybeAddContainerType(container_type));
Christopher Wiley4582ecb2015-09-25 13:27:45 -070061 // This should work.
Christopher Wiley9ab06232016-01-27 14:55:18 -080062 EXPECT_TRUE(types_.HasTypeByCanonicalName("java.util.List<a.goog.Foo>"));
Christopher Wiley4582ecb2015-09-25 13:27:45 -070063}
64
Christopher Wileydb154a52015-09-28 16:32:25 -070065} // namespace java
Christopher Wiley4582ecb2015-09-25 13:27:45 -070066} // namespace android
67} // namespace aidl