Imported Upstream version 1.8.0
[platform/core/ml/nnfw.git] / compiler / luci / lang / src / Module.test.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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 "luci/IR/Module.h"
18
19 #include <gtest/gtest.h>
20
21 TEST(ModuleTest, consturctor)
22 {
23   auto gs = luci::make_module();
24
25   SUCCEED();
26 }
27
28 TEST(ModuleTest, add)
29 {
30   auto m = luci::make_module();
31   auto g = loco::make_graph();
32   auto g_ptr = g.get();
33
34   m->add(std::move(g));
35
36   ASSERT_EQ(g_ptr, m->graph());
37   ASSERT_EQ(g_ptr, m->graph(0));
38 }
39
40 TEST(ModuleTest, add_more)
41 {
42   auto m = luci::make_module();
43   auto g1 = loco::make_graph();
44   auto g2 = loco::make_graph();
45   auto g3 = loco::make_graph();
46   auto g1_ptr = g1.get();
47   auto g2_ptr = g2.get();
48   auto g3_ptr = g3.get();
49
50   m->add(std::move(g1));
51   m->add(std::move(g2));
52   m->add(std::move(g3));
53
54   ASSERT_EQ(3, m->size());
55   ASSERT_EQ(g1_ptr, m->graph());
56   ASSERT_EQ(g1_ptr, m->graph(0));
57   ASSERT_EQ(g2_ptr, m->graph(1));
58   ASSERT_EQ(g3_ptr, m->graph(2));
59 }
60
61 TEST(ModuleTest, add_nullptr_NEG)
62 {
63   auto m = luci::make_module();
64
65   EXPECT_THROW(m->add(nullptr), std::invalid_argument);
66 }
67
68 TEST(ModuleTest, graph_index_overflow_NEG)
69 {
70   auto m = luci::make_module();
71
72   EXPECT_ANY_THROW(m->graph(100));
73 }