1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 // -*- Mode: C++ -*-
3 //
4 // Copyright (C) 2013-2020 Red Hat, Inc.
5
6 /// @file
7 ///
8 /// This is a collection of unit tests for functions defined in
9 /// abg-tgools-utils.cc.
10
11 #include <iostream>
12 #include "abg-tools-utils.h"
13
14 using namespace abigail::tools_utils;
15 using std::cerr;
16
17 int
main(int,char **)18 main(int, char**)
19 {
20
21 /// These are unit tests for abigail::tools_utils::decl_names_equal.
22 /// Just run the resulting runtesttoolsutils program under the
23 /// debugger to debug this if need be.
24
25 ABG_ASSERT(decl_names_equal("foo", "foo") == true);
26
27 ABG_ASSERT(decl_names_equal("foo", "bar") == false);
28
29 ABG_ASSERT(decl_names_equal("__anonymous_struct__1::foo",
30 "__anonymous_struct__2::foo") == true);
31
32 ABG_ASSERT(decl_names_equal
33 ("__anonymous_struct__1::foo::__anonymous_struct__2::bar",
34 "__anonymous_struct__10::foo::__anonymous_struct__11::bar")
35 == true);
36
37 ABG_ASSERT(decl_names_equal
38 ("__anonymous_union__1::foo::__anonymous_union__2::bar",
39 "__anonymous_union__10::foo::__anonymous_union__11::bar")
40 == true);
41
42 ABG_ASSERT(decl_names_equal
43 ("__anonymous_enum__1::foo::__anonymous_enum__2::bar",
44 "__anonymous_enum__10::foo::__anonymous_enum__11::bar")
45 == true);
46
47 ABG_ASSERT(decl_names_equal
48 ("__anonymous_struct__1::bar::__anonymous_struct__2::baz",
49 "__anonymous_struct__10::foo::__anonymous_struct__11::bar")
50 == false);
51
52 ABG_ASSERT(decl_names_equal
53 ("__anonymous_struct__1::foo::__anonymous_struct__2::baz",
54 "__anonymous_struct__10::foo::__anonymous_struct__11::bar")
55 == false);
56
57 ABG_ASSERT(decl_names_equal
58 ("__anonymous_struct__1::foo::__anonymous_struct__2::bar",
59 "__anonymous_struct__10::foo::__anonymous_union__11::bar")
60 == false);
61
62 ABG_ASSERT(decl_names_equal
63 ("__anonymous_struct__1::foo::__anonymous_struct__2::bar",
64 "__anonymous_struct__10::foo::__anonymous_enum__11::bar")
65 == false);
66
67 ABG_ASSERT(decl_names_equal
68 ("OT::Extension<OT::ExtensionSubst>::__anonymous_union__",
69 "OT::Extension<OT::ExtensionSubst>::__anonymous_union__")
70 == true);
71
72 ABG_ASSERT(decl_names_equal("S0::m2", "S0::m12") == false);
73
74 ABG_ASSERT(!decl_names_equal("S0::S1", "S0"));
75 ABG_ASSERT(!decl_names_equal("S0", "S0::S1"));
76 ABG_ASSERT(!decl_names_equal("S1::S0", "S0::S1"));
77 ABG_ASSERT(!decl_names_equal("__anonymous_struct__::S0", "__anonymous_struct__"));
78 ABG_ASSERT(!decl_names_equal("__anonymous_struct__", "__anonymous_struct__::S1"));
79 ABG_ASSERT(!decl_names_equal("__anonymous_struct__::S0", "__anonymous_struct__::S1"));
80 ABG_ASSERT(!decl_names_equal("S0::__anonymous_struct__", "__anonymous_struct__"));
81 ABG_ASSERT(!decl_names_equal("__anonymous_struct__", "S1::__anonymous_struct__"));
82 ABG_ASSERT(!decl_names_equal("S0::__anonymous_struct__", "S1::__anonymous_struct__"));
83
84 return 0;
85 }
86