Skip to content

Commit

Permalink
Adds Windows/MSVC support. (amazon-ion#91)
Browse files Browse the repository at this point in the history
* Adds Windows/MSVC support.

* Adds appveyor config.
  • Loading branch information
tgregg authored Nov 21, 2017
1 parent d7ee853 commit 2a2f903
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 30 deletions.
19 changes: 19 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '1.0.{build}'

image: Visual Studio 2017

platform:
- x64

configuration:
- Debug

install:
- git submodule update --init --recursive

build_script:
- cmake -G "Visual Studio 15 2017 Win64" .
- cmake --build %APPVEYOR_BUILD_FOLDER% --config %CONFIGURATION%

test_script:
- '%APPVEYOR_BUILD_FOLDER%\test\%CONFIGURATION%\all_tests.exe'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ build/
cmake-build-debug/
cmake-build-release/
install_manifest.txt
.vs/
CMakeSettings.json
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ cmake_minimum_required(VERSION 3.2)

project(IonC)

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 -Wall")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -O0 -Wall")
set(BUILD_SHARED_LIBS ON)
if (MSVC)
else()
set(BUILD_SHARED_LIBS ON)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 -Wall")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -O0 -Wall")
endif()

add_subdirectory(decNumber)
add_subdirectory(ionc)
Expand Down
9 changes: 7 additions & 2 deletions ionc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ set_property(TARGET ionc PROPERTY C_STANDARD 99)
target_include_directories(ionc PUBLIC
.
inc/

)
target_link_libraries(ionc decNumber m)

if (MSVC)
target_link_libraries(ionc decNumber)
else()
# Unix requires linking against lib m explicitly.
target_link_libraries(ionc decNumber m)
endif()

install(TARGETS ionc
DESTINATION lib)
Expand Down
7 changes: 2 additions & 5 deletions ionc/ion_float.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
*/

#include "ion.h"

#define ION_FLOAT_NEG_ZERO_DOUBLE 0x8000000000000000
#include <math.h>

BOOL ion_float_is_negative_zero(double value) {
long neg_zero_bits = ION_FLOAT_NEG_ZERO_DOUBLE;
return !memcmp(&neg_zero_bits, &value, sizeof(double));
return value == 0.0 && signbit(value);
}

19 changes: 12 additions & 7 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@

# Avoid macro definition collisions between ionc and googletest.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGTEST_DONT_DEFINE_SUCCEED=1 -DGTEST_DONT_DEFINE_FAIL=1")

# Disable verbose parameterized test names in debug configuration. These don't always integrate well with IDEs
# (e.g. CLion), but are nice to have from the command line.
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 -Wall")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -O0 -Wall")

add_subdirectory(googletest)
# Verbose parameterized names are disabled in debug configuration and on Windows. These don't
# always integrate well with IDEs (e.g. CLion), but are nice to have from the command line.
if (MSVC)
# Prevent googletest from linking against different versions of the C Runtime Library on
# Windows.
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
else()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0 -Wall")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -O0 -Wall")
endif()

add_executable(all_tests
gather_vectors.cpp
Expand All @@ -21,6 +24,8 @@ add_executable(all_tests
test_ion_extractor.cpp
)

add_subdirectory(googletest)

include_directories(
.
googletest/googletest/include/gtest
Expand Down
16 changes: 8 additions & 8 deletions test/gather_vectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
* language governing permissions and limitations under the License.
*/

#include "gather_vectors.h"
#include "ion_helpers.h"
#include <cstdarg>
#include <sys/stat.h>

#ifdef ION_PLATFORM_WINDOWS
#include <io.h>
#else
#include <dirent.h>
#endif

#include "gather_vectors.h"
#include "ion_helpers.h"
#include <cstdarg>
#include <sys/stat.h>

//============================================================================
// File handling utilities

Expand Down Expand Up @@ -269,7 +269,7 @@ typedef struct _dir {
#define DIR_CLOSE(pdir) win_close(pdir)
void win_close(DIR *pdir);

char *win_fixname(char *pname)
char *win_fixname(const char *pname)
{
char *cp, *fixedname;
int32_t len;
Expand All @@ -278,7 +278,7 @@ char *win_fixname(char *pname)
len = strlen(pname);
if (len < 0) return NULL;

fixedname = malloc(len + 5); // + 5 for: '/' "*.*" '\0'
fixedname = (char *)malloc(len + 5); // + 5 for: '/' "*.*" '\0'
if (!fixedname) return NULL;

memcpy(fixedname, pname, len + 1);
Expand All @@ -289,7 +289,7 @@ char *win_fixname(char *pname)
return fixedname;
}

DIR *win_open(char *pname)
DIR *win_open(const char *pname)
{
char *fixedname = win_fixname(pname);
DIR *pdir = (DIR *)malloc(sizeof(DIR));
Expand Down
8 changes: 4 additions & 4 deletions test/ion_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@
#define ION_EXPECT_DOUBLE_EQ(x, y) { \
switch (assertion_type) { \
case ASSERTION_TYPE_NORMAL: \
EXPECT_TRUE(!(isnan(x) ^ isnan(y))); \
if (isnan(x) || isnan(y)) break; \
EXPECT_TRUE(!(std::isnan(x) ^ std::isnan(y))); \
if (std::isnan(x) || std::isnan(y)) break; \
EXPECT_TRUE(!(ion_float_is_negative_zero(x) ^ ion_float_is_negative_zero(y))); \
if (ion_float_is_negative_zero(x) || ion_float_is_negative_zero(y)) break; \
EXPECT_DOUBLE_EQ(x, y) << "Test: " << g_CurrentTest; \
break; \
case ASSERTION_TYPE_SET_FLAG: \
if (isnan(x) ^ isnan(y)) { \
if (std::isnan(x) ^ std::isnan(y)) { \
return FALSE; \
} \
if (isnan(x)) break; \
if (std::isnan(x)) break; \
if (ion_float_is_negative_zero(x) ^ ion_float_is_negative_zero(y)) { \
return FALSE; \
} \
Expand Down
60 changes: 60 additions & 0 deletions test/test_vectors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* language governing permissions and limitations under the License.
*/

#include "ion_platform_config.h"
#include "gather_vectors.h"
#include "ion_event_stream.h"
#include "ion_assert.h"
Expand Down Expand Up @@ -224,6 +225,17 @@ TEST_P(GoodBasicVector, GoodBasic) {
}
}

#ifdef ION_PLATFORM_WINDOWS
INSTANTIATE_TEST_CASE_P(
TestVectors,
GoodBasicVector,
::testing::Combine(
::testing::ValuesIn(gather(FILETYPE_ALL, CLASSIFICATION_GOOD_BASIC)),
::testing::Values(READ, ROUNDTRIP_TEXT, ROUNDTRIP_BINARY),
::testing::Values(STREAM, BUFFER)
)
);
#else
INSTANTIATE_TEST_CASE_P(
TestVectors,
GoodBasicVector,
Expand All @@ -236,6 +248,7 @@ INSTANTIATE_TEST_CASE_P(
, GoodVectorToString()
#endif
);
#endif


typedef void (*COMPARISON_FN)(IonEventStream *stream, size_t index_expected, size_t index_actual);
Expand Down Expand Up @@ -371,6 +384,17 @@ TEST_P(GoodEquivsVector, GoodEquivs) {
}
}

#ifdef ION_PLATFORM_WINDOWS
INSTANTIATE_TEST_CASE_P(
TestVectors,
GoodEquivsVector,
::testing::Combine(
::testing::ValuesIn(gather(FILETYPE_ALL, CLASSIFICATION_GOOD_EQUIVS)),
::testing::Values(READ, ROUNDTRIP_TEXT, ROUNDTRIP_BINARY),
::testing::Values(STREAM, BUFFER)
)
);
#else
INSTANTIATE_TEST_CASE_P(
TestVectors,
GoodEquivsVector,
Expand All @@ -383,6 +407,7 @@ INSTANTIATE_TEST_CASE_P(
, GoodVectorToString()
#endif
);
#endif

/**
* Exercises good vectors with equivTimeline semantics. This means that timestamps are compared for instant equivalence
Expand All @@ -403,6 +428,17 @@ TEST_P(GoodTimestampEquivTimelineVector, GoodTimestampEquivTimeline) {
}
}

#ifdef ION_PLATFORM_WINDOWS
INSTANTIATE_TEST_CASE_P(
TestVectors,
GoodTimestampEquivTimelineVector,
::testing::Combine(
::testing::ValuesIn(gather(FILETYPE_ALL, CLASSIFICATION_GOOD_TIMESTAMP_EQUIVTIMELINE)),
::testing::Values(READ, ROUNDTRIP_TEXT, ROUNDTRIP_BINARY),
::testing::Values(STREAM, BUFFER)
)
);
#else
INSTANTIATE_TEST_CASE_P(
TestVectors,
GoodTimestampEquivTimelineVector,
Expand All @@ -415,6 +451,7 @@ INSTANTIATE_TEST_CASE_P(
, GoodVectorToString()
#endif
);
#endif

/**
* Exercises good vectors with nonequivs semantics.
Expand All @@ -433,6 +470,17 @@ TEST_P(GoodNonequivsVector, GoodNonequivs) {
}
}

#ifdef ION_PLATFORM_WINDOWS
INSTANTIATE_TEST_CASE_P(
TestVectors,
GoodNonequivsVector,
::testing::Combine(
::testing::ValuesIn(gather(FILETYPE_ALL, CLASSIFICATION_GOOD_NONEQUIVS)),
::testing::Values(READ, ROUNDTRIP_TEXT, ROUNDTRIP_BINARY),
::testing::Values(STREAM, BUFFER)
)
);
#else
INSTANTIATE_TEST_CASE_P(
TestVectors,
GoodNonequivsVector,
Expand All @@ -445,6 +493,7 @@ INSTANTIATE_TEST_CASE_P(
, GoodVectorToString()
#endif
);
#endif

/**
* Exercises bad vectors. Bad vectors must fail to parse in order to succeed the test.
Expand All @@ -454,6 +503,16 @@ TEST_P(BadVector, Bad) {
EXPECT_NE(IERR_OK, status) << test_name << " FAILED" << std::endl;
}

#ifdef ION_PLATFORM_WINDOWS
INSTANTIATE_TEST_CASE_P(
TestVectors,
BadVector,
::testing::Combine(
::testing::ValuesIn(gather(FILETYPE_ALL, CLASSIFICATION_BAD)),
::testing::Values(STREAM, BUFFER)
)
);
#else
INSTANTIATE_TEST_CASE_P(
TestVectors,
BadVector,
Expand All @@ -465,3 +524,4 @@ INSTANTIATE_TEST_CASE_P(
, BadVectorToString()
#endif
);
#endif
8 changes: 7 additions & 1 deletion tools/ionizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,11 @@ set_property(TARGET ionizer PROPERTY C_STANDARD 99)
target_include_directories(ionizer PRIVATE
.
)
target_link_libraries(ionizer ionc m)

if (MSVC)
target_link_libraries(ionizer ionc)
else()
# Unix requires linking against lib m explicitly.
target_link_libraries(ionizer ionc)
endif()

0 comments on commit 2a2f903

Please sign in to comment.