瀏覽代碼

Add compile/link test code

DarkMorford 5 年之前
父節點
當前提交
e9cb767f6c
共有 3 個文件被更改,包括 63 次插入0 次删除
  1. 17 0
      test_package/CMakeLists.txt
  2. 24 0
      test_package/conanfile.py
  3. 22 0
      test_package/example.cpp

+ 17 - 0
test_package/CMakeLists.txt

@@ -0,0 +1,17 @@
+cmake_minimum_required(VERSION 3.1.2)
+project(PackageTest CXX)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup()
+
+if(${CMAKE_EXPORT_NO_PACKAGE_REGISTRY})
+endif()
+
+add_executable(example example.cpp)
+target_link_libraries(example ${CONAN_LIBS})
+
+# CTest is a testing tool that can be used to test your project.
+# enable_testing()
+# add_test(NAME example
+#          WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
+#          COMMAND example)

+ 24 - 0
test_package/conanfile.py

@@ -0,0 +1,24 @@
+from conans import ConanFile, CMake, tools
+import os
+
+
+class LibOggTestConan(ConanFile):
+    settings = "os", "compiler", "build_type", "arch"
+    generators = "cmake"
+
+    def build(self):
+        cmake = CMake(self)
+        # Current dir is "test_package/build/<build_id>" and CMakeLists.txt is
+        # in "test_package"
+        cmake.configure()
+        cmake.build()
+
+    def imports(self):
+        self.copy("*.dll", dst="bin", src="bin")
+        self.copy("*.dylib*", dst="bin", src="lib")
+        self.copy('*.so*', dst='bin', src='lib')
+
+    def test(self):
+        if not tools.cross_building(self.settings):
+            os.chdir("bin")
+            self.run(f".{os.sep}example")

+ 22 - 0
test_package/example.cpp

@@ -0,0 +1,22 @@
+#include <ogg/ogg.h>
+
+#define CONAN_OGGCHECK(x) if ((x) != 0) return x
+
+int main() {
+    int ogg_success;
+    ogg_stream_state stream;
+
+    ogg_success = ogg_stream_init(&stream, 1);
+    CONAN_OGGCHECK(ogg_success);
+
+    ogg_success = ogg_stream_check(&stream);
+    CONAN_OGGCHECK(ogg_success);
+
+    ogg_success = ogg_stream_reset(&stream);
+    CONAN_OGGCHECK(ogg_success);
+
+    ogg_success = ogg_stream_clear(&stream);
+    CONAN_OGGCHECK(ogg_success);
+
+    return 0;
+}