IGNITE-3140: CPP: Added tests for string format validity.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/cbb77c9a Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/cbb77c9a Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/cbb77c9a Branch: refs/heads/ignite-1232 Commit: cbb77c9ad860bc8675077b09410e6e344f36bbb4 Parents: 34fc31e Author: vozerov-gridgain <[email protected]> Authored: Tue Jun 28 12:36:56 2016 +0300 Committer: vozerov-gridgain <[email protected]> Committed: Tue Jun 28 12:36:56 2016 +0300 ---------------------------------------------------------------------- modules/platforms/cpp/core-test/Makefile.am | 1 + .../cpp/core-test/project/vs/core-test.vcxproj | 1 + .../project/vs/core-test.vcxproj.filters | 3 + .../cpp/core-test/src/interop_test.cpp | 148 +++++++++++++++++++ 4 files changed, 153 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/cbb77c9a/modules/platforms/cpp/core-test/Makefile.am ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/Makefile.am b/modules/platforms/cpp/core-test/Makefile.am index d1f4ca5..759be13 100644 --- a/modules/platforms/cpp/core-test/Makefile.am +++ b/modules/platforms/cpp/core-test/Makefile.am @@ -52,6 +52,7 @@ ignite_tests_SOURCES = \ src/concurrent_test.cpp \ src/ignition_test.cpp \ src/interop_memory_test.cpp \ + src/interop_test.cpp \ src/handle_registry_test.cpp \ src/ignite_error_test.cpp \ src/binary_test_defs.cpp \ http://git-wip-us.apache.org/repos/asf/ignite/blob/cbb77c9a/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj b/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj index edf87ba..a7ffad8 100644 --- a/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj +++ b/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj @@ -45,6 +45,7 @@ <ClCompile Include="..\..\src\binary_test_defs.cpp" /> <ClCompile Include="..\..\src\cache_query_test.cpp" /> <ClCompile Include="..\..\src\interop_memory_test.cpp" /> + <ClCompile Include="..\..\src\interop_test.cpp" /> <ClCompile Include="..\..\src\teamcity_boost.cpp" /> <ClCompile Include="..\..\src\teamcity_messages.cpp" /> <ClCompile Include="..\..\src\transactions_test.cpp" /> http://git-wip-us.apache.org/repos/asf/ignite/blob/cbb77c9a/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj.filters ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj.filters b/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj.filters index 2259f4c..39e2aee 100644 --- a/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj.filters +++ b/modules/platforms/cpp/core-test/project/vs/core-test.vcxproj.filters @@ -43,6 +43,9 @@ <ClCompile Include="..\..\src\transactions_test.cpp"> <Filter>Code</Filter> </ClCompile> + <ClCompile Include="..\..\src\interop_test.cpp"> + <Filter>Code</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\include\teamcity_messages.h"> http://git-wip-us.apache.org/repos/asf/ignite/blob/cbb77c9a/modules/platforms/cpp/core-test/src/interop_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/interop_test.cpp b/modules/platforms/cpp/core-test/src/interop_test.cpp new file mode 100644 index 0000000..4b079d9 --- /dev/null +++ b/modules/platforms/cpp/core-test/src/interop_test.cpp @@ -0,0 +1,148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 _MSC_VER +# define BOOST_TEST_DYN_LINK +#endif + +#include <boost/test/unit_test.hpp> + +#include "ignite/ignition.h" + +using namespace ignite; +using namespace cache; +using namespace boost::unit_test; + +void InitConfig(IgniteConfiguration& cfg) +{ + cfg.jvmOpts.push_back("-Xdebug"); + cfg.jvmOpts.push_back("-Xnoagent"); + cfg.jvmOpts.push_back("-Djava.compiler=NONE"); + cfg.jvmOpts.push_back("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"); + cfg.jvmOpts.push_back("-XX:+HeapDumpOnOutOfMemoryError"); + +#ifdef IGNITE_TESTS_32 + cfg.jvmInitMem = 256; + cfg.jvmMaxMem = 768; +#else + cfg.jvmInitMem = 1024; + cfg.jvmMaxMem = 4096; +#endif + + char* cfgPath = getenv("IGNITE_NATIVE_TEST_CPP_CONFIG_PATH"); + + cfg.springCfgPath = std::string(cfgPath).append("/").append("cache-test.xml"); +} + +BOOST_AUTO_TEST_SUITE(InteropTestSuite) + +#ifdef ENABLE_STRING_SERIALIZATION_VER_2_TESTS + +BOOST_AUTO_TEST_CASE(StringUtfInvalidSequence) +{ + IgniteConfiguration cfg; + + InitConfig(cfg); + + Ignite ignite = Ignition::Start(cfg); + + Cache<std::string, std::string> cache = ignite.CreateCache<std::string, std::string>("Test"); + + std::string initialValue; + + initialValue.push_back(static_cast<unsigned char>(0xD8)); + initialValue.push_back(static_cast<unsigned char>(0x00)); + + try + { + cache.Put("key", initialValue); + + std::string cachedValue = cache.Get("key"); + + BOOST_ERROR("Exception is expected due to invalid format."); + } + catch (const IgniteError&) + { + // Expected in this mode. + } + + Ignition::StopAll(false); +} + +BOOST_AUTO_TEST_CASE(StringUtfInvalidCodePoint) +{ + IgniteConfiguration cfg; + + InitConfig(cfg); + + putenv("IGNITE_BINARY_MARSHALLER_USE_STRING_SERIALIZATION_VER_2=true"); + + Ignite ignite = Ignition::Start(cfg); + + Cache<std::string, std::string> cache = ignite.CreateCache<std::string, std::string>("Test"); + + std::string initialValue; + + // 1110xxxx 10xxxxxx 10xxxxxx | + // <= 11011000 00000000 | U+D8 + // = 11101101 10100000 10000000 | ED A0 80 + initialValue.push_back(static_cast<unsigned char>(0xED)); + initialValue.push_back(static_cast<unsigned char>(0xA0)); + initialValue.push_back(static_cast<unsigned char>(0x80)); + + cache.Put("key", initialValue); + std::string cachedValue = cache.Get("key"); + + // This is a valid case. Invalid code points are supported in this mode. + BOOST_CHECK_EQUAL(initialValue, cachedValue); + + Ignition::StopAll(false); +} + +#endif + +BOOST_AUTO_TEST_CASE(StringUtfValid4ByteCodePoint) +{ + IgniteConfiguration cfg; + + InitConfig(cfg); + + Ignite ignite = Ignition::Start(cfg); + + Cache<std::string, std::string> cache = ignite.CreateCache<std::string, std::string>("Test"); + + std::string initialValue; + + // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx | + // <= 00001 00000001 01001011 | U+1014B + // <= 000 010000 000101 001011 | U+1014B + // = 11110000 10010000 10000101 10001011 | F0 90 85 8B + initialValue.push_back(static_cast<unsigned char>(0xF0)); + initialValue.push_back(static_cast<unsigned char>(0x90)); + initialValue.push_back(static_cast<unsigned char>(0x85)); + initialValue.push_back(static_cast<unsigned char>(0x8B)); + + cache.Put("key", initialValue); + std::string cachedValue = cache.Get("key"); + + // This is a valid UTF-8 code point. Should be supported in default mode. + BOOST_CHECK_EQUAL(initialValue, cachedValue); + + Ignition::StopAll(false); +} + +BOOST_AUTO_TEST_SUITE_END()
