From 90613a344570916a4a7d197dc20d3af31a38be51 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 1 Dec 2022 22:38:41 +0800 Subject: [PATCH] improve tests --- tests/projects/c++/shared_library/src/foo.cpp | 5 +++++ .../shared_library/src/{interface.h => foo.h} | 9 +-------- .../c++/shared_library/src/interface.cpp | 6 ------ tests/projects/c++/shared_library/src/main.cpp | 7 +++---- tests/projects/c++/shared_library/xmake.lua | 6 +++--- tests/projects/c++/static_library/src/foo.cpp | 5 +++++ tests/projects/c++/static_library/src/foo.h | 9 +++++++++ .../c++/static_library/src/interface.cpp | 6 ------ .../projects/c++/static_library/src/interface.h | 16 ---------------- tests/projects/c++/static_library/src/main.cpp | 7 +++---- tests/projects/c++/static_library/xmake.lua | 6 +++--- tests/projects/c/static_library/src/foo.c | 5 +++++ tests/projects/c/static_library/src/foo.h | 2 ++ tests/projects/c/static_library/src/interface.c | 6 ------ tests/projects/c/static_library/src/interface.h | 9 --------- .../c/static_library/src/{test.c => main.c} | 7 +++---- tests/projects/c/static_library/xmake.lua | 10 +++++----- 17 files changed, 47 insertions(+), 74 deletions(-) create mode 100644 tests/projects/c++/shared_library/src/foo.cpp rename tests/projects/c++/shared_library/src/{interface.h => foo.h} (66%) delete mode 100644 tests/projects/c++/shared_library/src/interface.cpp create mode 100644 tests/projects/c++/static_library/src/foo.cpp create mode 100644 tests/projects/c++/static_library/src/foo.h delete mode 100644 tests/projects/c++/static_library/src/interface.cpp delete mode 100644 tests/projects/c++/static_library/src/interface.h create mode 100644 tests/projects/c/static_library/src/foo.c create mode 100644 tests/projects/c/static_library/src/foo.h delete mode 100644 tests/projects/c/static_library/src/interface.c delete mode 100644 tests/projects/c/static_library/src/interface.h rename tests/projects/c/static_library/src/{test.c => main.c} (56%) diff --git a/tests/projects/c++/shared_library/src/foo.cpp b/tests/projects/c++/shared_library/src/foo.cpp new file mode 100644 index 00000000000..1a1fb3425c5 --- /dev/null +++ b/tests/projects/c++/shared_library/src/foo.cpp @@ -0,0 +1,5 @@ +#include "foo.h" + +int add(int a, int b) { + return a + b; +} diff --git a/tests/projects/c++/shared_library/src/interface.h b/tests/projects/c++/shared_library/src/foo.h similarity index 66% rename from tests/projects/c++/shared_library/src/interface.h rename to tests/projects/c++/shared_library/src/foo.h index 57b6194de11..20df0baa473 100644 --- a/tests/projects/c++/shared_library/src/interface.h +++ b/tests/projects/c++/shared_library/src/foo.h @@ -10,14 +10,7 @@ extern "C" { # define __export #endif -/*! calculate add(a, b) - * - * @param a the first argument - * @param b the second argument - * - * @return the result - */ -__export int add(int a, int b); +__export int add(int a, int b); #ifdef __cplusplus } diff --git a/tests/projects/c++/shared_library/src/interface.cpp b/tests/projects/c++/shared_library/src/interface.cpp deleted file mode 100644 index 598d07560a7..00000000000 --- a/tests/projects/c++/shared_library/src/interface.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "interface.h" - -int add(int a, int b) -{ - return a + b; -} diff --git a/tests/projects/c++/shared_library/src/main.cpp b/tests/projects/c++/shared_library/src/main.cpp index 72e03272b26..ed192478986 100644 --- a/tests/projects/c++/shared_library/src/main.cpp +++ b/tests/projects/c++/shared_library/src/main.cpp @@ -1,10 +1,9 @@ -#include "interface.h" +#include "foo.h" #include using namespace std; -int main(int argc, char** argv) -{ - cout << "add(1, 2) = " << add(1, 2) << endl; +int main(int argc, char** argv) { + cout << "add(1, 2) = " << add(1, 2) << endl; return 0; } diff --git a/tests/projects/c++/shared_library/xmake.lua b/tests/projects/c++/shared_library/xmake.lua index 49641ced10e..f2e0a1d3d63 100644 --- a/tests/projects/c++/shared_library/xmake.lua +++ b/tests/projects/c++/shared_library/xmake.lua @@ -1,12 +1,12 @@ add_rules("mode.debug", "mode.release") -target("test") +target("foo") set_kind("shared") - add_files("src/interface.cpp") + add_files("src/foo.cpp") target("demo") set_kind("binary") - add_deps("test") + add_deps("foo") add_files("src/main.cpp") diff --git a/tests/projects/c++/static_library/src/foo.cpp b/tests/projects/c++/static_library/src/foo.cpp new file mode 100644 index 00000000000..1a1fb3425c5 --- /dev/null +++ b/tests/projects/c++/static_library/src/foo.cpp @@ -0,0 +1,5 @@ +#include "foo.h" + +int add(int a, int b) { + return a + b; +} diff --git a/tests/projects/c++/static_library/src/foo.h b/tests/projects/c++/static_library/src/foo.h new file mode 100644 index 00000000000..d2506bca987 --- /dev/null +++ b/tests/projects/c++/static_library/src/foo.h @@ -0,0 +1,9 @@ +#ifdef __cplusplus +extern "C" { +#endif + +int add(int a, int b); + +#ifdef __cplusplus +} +#endif diff --git a/tests/projects/c++/static_library/src/interface.cpp b/tests/projects/c++/static_library/src/interface.cpp deleted file mode 100644 index 598d07560a7..00000000000 --- a/tests/projects/c++/static_library/src/interface.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "interface.h" - -int add(int a, int b) -{ - return a + b; -} diff --git a/tests/projects/c++/static_library/src/interface.h b/tests/projects/c++/static_library/src/interface.h deleted file mode 100644 index 4a41e9597c6..00000000000 --- a/tests/projects/c++/static_library/src/interface.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifdef __cplusplus -extern "C" { -#endif - -/*! calculate add(a, b) - * - * @param a the first argument - * @param b the second argument - * - * @return the result - */ -int add(int a, int b); - -#ifdef __cplusplus -} -#endif diff --git a/tests/projects/c++/static_library/src/main.cpp b/tests/projects/c++/static_library/src/main.cpp index 72e03272b26..ed192478986 100644 --- a/tests/projects/c++/static_library/src/main.cpp +++ b/tests/projects/c++/static_library/src/main.cpp @@ -1,10 +1,9 @@ -#include "interface.h" +#include "foo.h" #include using namespace std; -int main(int argc, char** argv) -{ - cout << "add(1, 2) = " << add(1, 2) << endl; +int main(int argc, char** argv) { + cout << "add(1, 2) = " << add(1, 2) << endl; return 0; } diff --git a/tests/projects/c++/static_library/xmake.lua b/tests/projects/c++/static_library/xmake.lua index 184a33d510f..f31e08530fc 100644 --- a/tests/projects/c++/static_library/xmake.lua +++ b/tests/projects/c++/static_library/xmake.lua @@ -1,12 +1,12 @@ add_rules("mode.debug", "mode.release") -target("test") +target("foo") set_kind("static") - add_files("src/interface.cpp") + add_files("src/foo.cpp") target("demo") set_kind("binary") - add_deps("test") + add_deps("foo") add_files("src/main.cpp") diff --git a/tests/projects/c/static_library/src/foo.c b/tests/projects/c/static_library/src/foo.c new file mode 100644 index 00000000000..1a1fb3425c5 --- /dev/null +++ b/tests/projects/c/static_library/src/foo.c @@ -0,0 +1,5 @@ +#include "foo.h" + +int add(int a, int b) { + return a + b; +} diff --git a/tests/projects/c/static_library/src/foo.h b/tests/projects/c/static_library/src/foo.h new file mode 100644 index 00000000000..16d451cbb6b --- /dev/null +++ b/tests/projects/c/static_library/src/foo.h @@ -0,0 +1,2 @@ +int add(int a, int b); + diff --git a/tests/projects/c/static_library/src/interface.c b/tests/projects/c/static_library/src/interface.c deleted file mode 100644 index 598d07560a7..00000000000 --- a/tests/projects/c/static_library/src/interface.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "interface.h" - -int add(int a, int b) -{ - return a + b; -} diff --git a/tests/projects/c/static_library/src/interface.h b/tests/projects/c/static_library/src/interface.h deleted file mode 100644 index 915f44b87b0..00000000000 --- a/tests/projects/c/static_library/src/interface.h +++ /dev/null @@ -1,9 +0,0 @@ -/*! calculate add(a, b) - * - * @param a the first argument - * @param b the second argument - * - * @return the result - */ -int add(int a, int b); - diff --git a/tests/projects/c/static_library/src/test.c b/tests/projects/c/static_library/src/main.c similarity index 56% rename from tests/projects/c/static_library/src/test.c rename to tests/projects/c/static_library/src/main.c index d438027e836..a4c76940856 100644 --- a/tests/projects/c/static_library/src/test.c +++ b/tests/projects/c/static_library/src/main.c @@ -1,8 +1,7 @@ -#include "interface.h" +#include "foo.h" #include - -int main(int argc, char** argv) -{ + +int main(int argc, char** argv) { printf("add(1, 2) = %d\n", add(1, 2)); return 0; } diff --git a/tests/projects/c/static_library/xmake.lua b/tests/projects/c/static_library/xmake.lua index 67081b1c26f..3aa16f1e733 100644 --- a/tests/projects/c/static_library/xmake.lua +++ b/tests/projects/c/static_library/xmake.lua @@ -1,12 +1,12 @@ add_rules("mode.release", "mode.debug") -target("static_library_c") +target("foo") set_kind("static") - add_files("src/interface.c") + add_files("src/foo.c") -target("test") +target("demo") set_kind("binary") - add_deps("static_library_c") - add_files("src/test.c") + add_deps("foo") + add_files("src/main.c")