• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2022 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 #include <gtest/gtest.h>
17 
18 #include "host/commands/cvd/selector/instance_group_record.h"
19 #include "host/commands/cvd/selector/instance_record.h"
20 
21 namespace cuttlefish {
22 namespace selector {
23 
24 /**
25  * Note that invalid inputs must be tested at the InstanceDatabase level
26  */
TEST(CvdInstanceRecordUnitTest,Fields)27 TEST(CvdInstanceRecordUnitTest, Fields) {
28   LocalInstanceGroup parent_group(
29       {.group_name = "super",
30        .home_dir = "/home/user",
31        .host_artifacts_path = "/home/user/download/bin",
32        .product_out_path = "/home/user/download/bin"});
33   if (!parent_group.AddInstance(3, "phone").ok()) {
34     /*
35      * Here's why we skip the test rather than see it as a failure.
36      *
37      * 1. The test is specifically designed for operations in
38      *    LocalInstanceRecord.
39      * 2. Adding instance to a group is tested in another test suites designed
40      *    for LocalInstanceGroup. It's a failure there but not here.
41      *
42      */
43     GTEST_SKIP() << "Failed to add instance group. Set up failed.";
44   }
45   auto& instances = parent_group.Instances();
46   auto& instance = *instances.cbegin();
47 
48   ASSERT_EQ(instance->InstanceId(), 3);
49   ASSERT_EQ(instance->InternalName(), "3");
50   ASSERT_EQ(instance->PerInstanceName(), "phone");
51   ASSERT_EQ(instance->InternalDeviceName(), "cvd-3");
52   ASSERT_EQ(instance->DeviceName(), "super-phone");
53   ASSERT_EQ(std::addressof(instance->ParentGroup()),
54             std::addressof(parent_group));
55 }
56 
57 /**
58  * Note that invalid inputs must be tested at the InstanceDatabase level
59  */
TEST(CvdInstanceRecordUnitTest,Copy)60 TEST(CvdInstanceRecordUnitTest, Copy) {
61   LocalInstanceGroup parent_group(
62       {.group_name = "super",
63        .home_dir = "/home/user",
64        .host_artifacts_path = "/home/user/download/bin",
65        .product_out_path = "/home/user/download/bin"});
66   if (!parent_group.AddInstance(3, "phone").ok()) {
67     /*
68      * Here's why we skip the test rather than see it as a failure.
69      *
70      * 1. The test is specifically designed for operations in
71      *    LocalInstanceRecord.
72      * 2. Adding instance to a group is tested in another test suites designed
73      *    for LocalInstanceGroup. It's a failure there but not here.
74      *
75      */
76     GTEST_SKIP() << "Failed to add instance group. Set up failed.";
77   }
78   auto& instances = parent_group.Instances();
79   auto& instance = *instances.cbegin();
80   auto copy = instance->GetCopy();
81 
82   ASSERT_EQ(instance->InstanceId(), copy.InstanceId());
83   ASSERT_EQ(instance->InternalName(), copy.InternalName());
84   ASSERT_EQ(instance->PerInstanceName(), copy.PerInstanceName());
85   ASSERT_EQ(instance->InternalDeviceName(), copy.InternalDeviceName());
86   ASSERT_EQ(instance->DeviceName(), copy.DeviceName());
87 }
88 
89 }  // namespace selector
90 }  // namespace cuttlefish
91