Added version and build info functions
authorArmin Novak <armin.novak@thincast.com>
Mon, 30 Mar 2015 15:50:47 +0000 (17:50 +0200)
committerArmin Novak <armin.novak@thincast.com>
Mon, 30 Mar 2015 15:51:29 +0000 (17:51 +0200)
Added functions to get
 * Version String
 * Build Time String
 * Git Revision String
and appropriate tests.

include/freerdp/freerdp.h
libfreerdp/core/CMakeLists.txt
libfreerdp/core/freerdp.c
winpr/include/CMakeLists.txt
winpr/include/winpr/version.h.in [new file with mode: 0644]
winpr/include/winpr/winpr.h
winpr/libwinpr/utils/CMakeLists.txt
winpr/libwinpr/utils/test/CMakeLists.txt
winpr/libwinpr/utils/test/TestVersion.c [new file with mode: 0644]
winpr/libwinpr/utils/winpr.c [new file with mode: 0644]

index 3f9359f..ee7f0fa 100644 (file)
@@ -260,6 +260,9 @@ FREERDP_API UINT32 freerdp_error_info(freerdp* instance);
 FREERDP_API void freerdp_set_error_info(rdpRdp* rdp, UINT32 error);
 
 FREERDP_API void freerdp_get_version(int* major, int* minor, int* revision);
+FREERDP_API char* freerdp_get_version_string(void);
+FREERDP_API char* freerdp_get_build_date(void);
+FREERDP_API char* freerdp_get_build_revision(void);
 
 FREERDP_API freerdp* freerdp_new(void);
 FREERDP_API void freerdp_free(freerdp* instance);
index 25bdb43..03ef096 100644 (file)
@@ -140,3 +140,7 @@ else()
 endif()
 
 freerdp_library_add(${OPENSSL_LIBRARIES})
+
+if(BUILD_TESTING)
+       add_subdirectory(test)
+endif()
index 6078df2..a4482b0 100644 (file)
@@ -394,6 +394,25 @@ void freerdp_get_version(int* major, int* minor, int* revision)
                *revision = FREERDP_VERSION_REVISION;
 }
 
+char* freerdp_get_version_string(void)
+{
+       return FREERDP_VERSION_FULL;
+}
+
+char* freerdp_get_build_date(void)
+{
+       static char build_date[64];
+
+       snprintf(build_date, sizeof(build_date), "%s %s", __DATE__, __TIME__);
+
+       return build_date;
+}
+
+char* freerdp_get_build_revision(void)
+{
+       return GIT_REVISION;
+}
+
 static wEventType FreeRDP_Events[] =
 {
        DEFINE_EVENT_ENTRY(WindowStateChange)
index f9ade23..3ce562e 100644 (file)
@@ -15,6 +15,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/winpr/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/winpr/version.h)
+
 file(GLOB WINPR_HEADERS "winpr/*.h")
 install(FILES ${WINPR_HEADERS} DESTINATION include/winpr COMPONENT headers)
 install(DIRECTORY winpr/tools DESTINATION include/winpr COMPONENT headers FILES_MATCHING PATTERN "*.h")
diff --git a/winpr/include/winpr/version.h.in b/winpr/include/winpr/version.h.in
new file mode 100644 (file)
index 0000000..45d7474
--- /dev/null
@@ -0,0 +1,32 @@
+/**
+ * FreeRDP: A Remote Desktop Protocol Implementation
+ * Version includes
+ *
+ * Copyright 2013 Thincast Technologies GmbH
+ * Copyright 2013 Bernhard Miklautz <bernhard.miklautz@thincast.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _WINPR_VERSION_H_
+#define _WINPR_VERSION_H_
+
+#define WINPR_VERSION_MAJOR ${WINPR_VERSION_MAJOR}
+#define WINPR_VERSION_MINOR ${WINPR_VERSION_MINOR}
+#define WINPR_VERSION_REVISION ${WINPR_VERSION_REVISION}
+#define WINPR_VERSION_SUFFIX "${WINPR_VERSION_SUFFIX}"
+#define WINPR_API_VERSION "${WINPR_API_VERSION}"
+#define WINPR_VERSION "${WINPR_VERSION}"
+#define WINPR_VERSION_FULL "${WINPR_VERSION_FULL}"
+#define GIT_REVISION "${GIT_REVISION}"
+
+#endif // _WINPR_VERSION_H_
index 28dc8f4..07938d7 100644 (file)
@@ -47,4 +47,9 @@
 #define INLINE inline
 #endif
 
+WINPR_API void winpr_get_version(int* major, int* minor, int* revision);
+WINPR_API char* winpr_get_version_string(void);
+WINPR_API char* winpr_get_build_date(void);
+WINPR_API char* winpr_get_build_revision(void);
+
 #endif /* WINPR_H */
index df1d270..e84365d 100644 (file)
@@ -86,6 +86,7 @@ set(${MODULE_PREFIX}_SRCS
        print.c
        stream.c
        debug.c
+       winpr.c
        cmdline.c
        ssl.c)
 
index 7679433..134015c 100644 (file)
@@ -6,6 +6,7 @@ set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c)
 
 set(${MODULE_PREFIX}_TESTS
        TestIni.c
+       TestVersion.c
        TestImage.c
        TestBipBuffer.c
        TestBacktrace.c
diff --git a/winpr/libwinpr/utils/test/TestVersion.c b/winpr/libwinpr/utils/test/TestVersion.c
new file mode 100644 (file)
index 0000000..0253bb2
--- /dev/null
@@ -0,0 +1,41 @@
+
+#include <winpr/crt.h>
+
+#include <winpr/version.h>
+#include <winpr/winpr.h>
+
+int TestVersion(int argc, char* argv[])
+{
+       char *version;
+       char *git;
+       char *build;
+       int major = 0, minor = 0, revision = 0;
+
+       winpr_get_version(&major, &minor, &revision);
+       if (major != WINPR_VERSION_MAJOR)
+               return -1;
+
+       if (minor != WINPR_VERSION_MINOR)
+               return -1;
+
+       if (revision != WINPR_VERSION_REVISION)
+               return -1;
+
+       version = winpr_get_version_string();
+       if (!version)
+               return -1;
+
+       git = winpr_get_build_revision();
+       if (!git)
+               return -1;
+
+       if (strncmp(git, GIT_REVISION, sizeof(GIT_REVISION)))
+               return -1;
+
+       build = winpr_get_build_date();
+       if (!build)
+               return -1;
+
+       return 0;
+}
+
diff --git a/winpr/libwinpr/utils/winpr.c b/winpr/libwinpr/utils/winpr.c
new file mode 100644 (file)
index 0000000..199f29e
--- /dev/null
@@ -0,0 +1,58 @@
+/**
+ * WinPR: Windows Portable Runtime
+ * Debugging Utils
+ *
+ * Copyright 2015 Armin Novak <armin.novak@thincast.com>
+ * Copyright 2015 Thincast Technologies GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <winpr/winpr.h>
+#include <winpr/version.h>
+
+void winpr_get_version(int* major, int* minor, int* revision)
+{
+       if (major)
+               *major = WINPR_VERSION_MAJOR;
+       if (minor)
+               *minor = WINPR_VERSION_MINOR;
+       if (revision)
+               *revision = WINPR_VERSION_REVISION;
+}
+
+char* winpr_get_version_string(void)
+{
+       return WINPR_VERSION_FULL;
+}
+
+char* winpr_get_build_date(void)
+{
+       static char build_date[64];
+
+       snprintf(build_date, sizeof(build_date), "%s %s", __DATE__, __TIME__);
+
+       return build_date;
+}
+
+char* winpr_get_build_revision(void)
+{
+       return GIT_REVISION;
+}
+