1 /*
2 * Copyright (C) 2021 Tetsuya Isaki
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
18 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
20 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
21 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26 #include "test.h"
27 #include "Diag.h"
28 #include "StringUtil.h"
29 #include <memory>
30
31 // テスト用のクラス
32 class Test;
33 class Test
34 {
35 public:
36 // コンストラクタの場合
Test()37 Test() {
38 name = string_format("%s", __method__);
39 }
40 // デストラクタの場合
~Test()41 ~Test() {
42 name = string_format("%s", __method__);
43 }
44
45 // ノーマルな関数
test1()46 void test1() {
47 name = string_format("%s", __method__);
48 }
49 // 紛らわしそうなやつ、ポインタを返す、同じクラスを受け取る
test2(Test * h)50 int *test2(Test *h) {
51 name = string_format("%s", __method__);
52 return NULL;
53 }
54 // 関数ポインタを受け取り、関数ポインタを返す
55 using func_t = int (*)();
test3(func_t a)56 func_t test3(func_t a) {
57 name = string_format("%s", __method__);
58 return NULL;
59 }
60
61 // 結果を格納する
62 static std::string name;
63 };
64
65 std::string Test::name;
66
67 void
test_get_classfunc_name()68 test_get_classfunc_name()
69 {
70 printf("%s\n", __func__);
71
72 std::unique_ptr<Test> t(new Test());
73 xp_eq("Test::Test", Test::name);
74
75 t->test1();
76 xp_eq("Test::test1", Test::name);
77
78 t->test2(NULL);
79 xp_eq("Test::test2", Test::name);
80
81 t->test3(NULL);
82 xp_eq("Test::test3", Test::name);
83
84 t.reset();
85 xp_eq("Test::~Test", Test::name);
86 }
87
88 void
test_Diag()89 test_Diag()
90 {
91 test_get_classfunc_name();
92 }
93