Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4144218296 for ; Tue, 10 Nov 2015 04:27:28 +0000 (UTC) Received: (qmail 66445 invoked by uid 500); 10 Nov 2015 04:27:28 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 66364 invoked by uid 500); 10 Nov 2015 04:27:28 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 65888 invoked by uid 99); 10 Nov 2015 04:27:27 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Nov 2015 04:27:27 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 42A76E0AD4; Tue, 10 Nov 2015 04:27:27 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: akuznetsov@apache.org To: commits@ignite.apache.org Date: Tue, 10 Nov 2015 04:27:38 -0000 Message-Id: <40ad27986fbf45a3afbfbc71b1d5c8f1@git.apache.org> In-Reply-To: <2e7418befe28469eb676b051f3101d37@git.apache.org> References: <2e7418befe28469eb676b051f3101d37@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [12/21] ignite git commit: IGNITE-1846: CPP: "portable" -> "binary", "metadata" -> "type". http://git-wip-us.apache.org/repos/asf/ignite/blob/303d79eb/modules/platforms/cpp/core-test/src/portable_reader_writer_raw_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/portable_reader_writer_raw_test.cpp b/modules/platforms/cpp/core-test/src/portable_reader_writer_raw_test.cpp deleted file mode 100644 index e93796f..0000000 --- a/modules/platforms/cpp/core-test/src/portable_reader_writer_raw_test.cpp +++ /dev/null @@ -1,1593 +0,0 @@ -/* - * 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 - -#include "ignite/impl/interop/interop.h" -#include "ignite/portable/portable.h" - -#include "ignite/portable_test_defs.h" -#include "ignite/portable_test_utils.h" - -using namespace ignite; -using namespace ignite::impl::interop; -using namespace ignite::impl::portable; -using namespace ignite::portable; -using namespace ignite_test::core::portable; - -template -void CheckRawPrimitive(T val) -{ - InteropUnpooledMemory mem(1024); - - InteropOutputStream out(&mem); - PortableWriterImpl writer(&out, NULL); - PortableRawWriter rawWriter(&writer); - - Write(rawWriter, val); - - out.Synchronize(); - - InteropInputStream in(&mem); - PortableReaderImpl reader(&in); - PortableRawReader rawReader(&reader); - - T readVal = Read(rawReader); - - BOOST_REQUIRE(readVal == val); -} - -template -void CheckRawPrimitiveArray(T dflt, T val1, T val2) -{ - InteropUnpooledMemory mem(1024); - - InteropOutputStream out(&mem); - PortableWriterImpl writer(&out, NULL); - PortableRawWriter rawWriter(&writer); - - InteropInputStream in(&mem); - PortableReaderImpl reader(&in); - PortableRawReader rawReader(&reader); - - // 1. Write NULL and see what happens. - WriteArray(rawWriter, NULL, 0); - - out.Synchronize(); - in.Synchronize(); - - BOOST_REQUIRE(ReadArray(rawReader, NULL, 0) == -1); - - in.Position(0); - BOOST_REQUIRE(ReadArray(rawReader, NULL, 2) == -1); - - T arr1[2]; - arr1[0] = dflt; - arr1[1] = dflt; - - in.Position(0); - BOOST_REQUIRE(ReadArray(rawReader, arr1, 1) == -1); - - BOOST_REQUIRE(arr1[0] == dflt); - BOOST_REQUIRE(arr1[1] == dflt); - - // 2. Write empty array. - T arr2[2]; - arr2[0] = val1; - arr2[1] = val2; - - out.Position(0); - in.Position(0); - - WriteArray(rawWriter, arr2, 0); - - out.Synchronize(); - in.Synchronize(); - - BOOST_REQUIRE(ReadArray(rawReader, NULL, 0) == 0); - - in.Position(0); - BOOST_REQUIRE(ReadArray(rawReader, NULL, 2) == 0); - - in.Position(0); - BOOST_REQUIRE(ReadArray(rawReader, arr1, 0) == 0); - BOOST_REQUIRE(arr1[0] == dflt); - BOOST_REQUIRE(arr1[1] == dflt); - - in.Position(0); - BOOST_REQUIRE(ReadArray(rawReader, arr1, 2) == 0); - BOOST_REQUIRE(arr1[0] == dflt); - BOOST_REQUIRE(arr1[1] == dflt); - - // 3. Partial array write. - out.Position(0); - in.Position(0); - - WriteArray(rawWriter, arr2, 1); - - out.Synchronize(); - in.Synchronize(); - - BOOST_REQUIRE(ReadArray(rawReader, NULL, 0) == 1); - BOOST_REQUIRE(ReadArray(rawReader, NULL, 2) == 1); - - BOOST_REQUIRE(ReadArray(rawReader, arr1, 0) == 1); - BOOST_REQUIRE(arr1[0] == dflt); - BOOST_REQUIRE(arr1[1] == dflt); - - BOOST_REQUIRE(ReadArray(rawReader, arr1, 1) == 1); - BOOST_REQUIRE(arr1[0] == val1); - BOOST_REQUIRE(arr1[1] == dflt); - arr1[0] = dflt; - - in.Position(0); - BOOST_REQUIRE(ReadArray(rawReader, arr1, 2) == 1); - BOOST_REQUIRE(arr1[0] == val1); - BOOST_REQUIRE(arr1[1] == dflt); - arr1[0] = dflt; - - // 4. Full array write. - out.Position(0); - in.Position(0); - - WriteArray(rawWriter, arr2, 2); - - out.Synchronize(); - in.Synchronize(); - - BOOST_REQUIRE(ReadArray(rawReader, NULL, 0) == 2); - BOOST_REQUIRE(ReadArray(rawReader, NULL, 2) == 2); - - BOOST_REQUIRE(ReadArray(rawReader, arr1, 0) == 2); - BOOST_REQUIRE(arr1[0] == dflt); - BOOST_REQUIRE(arr1[1] == dflt); - - BOOST_REQUIRE(ReadArray(rawReader, arr1, 1) == 2); - BOOST_REQUIRE(arr1[0] == dflt); - BOOST_REQUIRE(arr1[1] == dflt); - - BOOST_REQUIRE(ReadArray(rawReader, arr1, 2) == 2); - BOOST_REQUIRE(arr1[0] == val1); - BOOST_REQUIRE(arr1[1] == val2); -} - -void CheckRawWritesRestricted(PortableRawWriter& writer) -{ - try - { - writer.WriteInt8(1); - - BOOST_FAIL("Not restricted."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - int8_t arr[1]; - - writer.WriteInt8Array(arr, 1); - - BOOST_FAIL("Not restricted."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - Guid val(1, 1); - - writer.WriteGuid(val); - - BOOST_FAIL("Not restricted."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - writer.WriteString("test"); - - BOOST_FAIL("Not restricted."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - writer.WriteArray(); - - BOOST_FAIL("Not restricted."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - writer.WriteCollection(); - - BOOST_FAIL("Not restricted."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - writer.WriteMap(); - - BOOST_FAIL("Not restricted."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } -} - -void CheckRawReadsRestricted(PortableRawReader& reader) -{ - try - { - reader.ReadInt8(); - - BOOST_FAIL("Not restricted."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - int8_t arr[1]; - - reader.ReadInt8Array(arr, 1); - - BOOST_FAIL("Not restricted."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - reader.ReadGuid(); - - BOOST_FAIL("Not restricted."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - reader.ReadString(); - - BOOST_FAIL("Not restricted."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - reader.ReadArray(); - - BOOST_FAIL("Not restricted."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - reader.ReadCollection(); - - BOOST_FAIL("Not restricted."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - reader.ReadMap(); - - BOOST_FAIL("Not restricted."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } -} - -void CheckRawCollectionEmpty(CollectionType* colType) -{ - InteropUnpooledMemory mem(1024); - - InteropOutputStream out(&mem); - PortableWriterImpl writer(&out, NULL); - PortableRawWriter rawWriter(&writer); - - PortableCollectionWriter colWriter = colType ? - rawWriter.WriteCollection(*colType) : rawWriter.WriteCollection(); - - CheckRawWritesRestricted(rawWriter); - - colWriter.Close(); - - rawWriter.WriteInt8(1); - - try - { - colWriter.Write(1); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - colWriter.Close(); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - out.Synchronize(); - - InteropInputStream in(&mem); - PortableReaderImpl reader(&in); - PortableRawReader rawReader(&reader); - - PortableCollectionReader colReader = rawReader.ReadCollection(); - - if (colType) - BOOST_REQUIRE(colReader.GetType() == *colType); - else - BOOST_REQUIRE(colReader.GetType() == IGNITE_COLLECTION_UNDEFINED); - - BOOST_REQUIRE(colReader.GetSize() == 0); - BOOST_REQUIRE(!colReader.HasNext()); - BOOST_REQUIRE(!colReader.IsNull()); - - try - { - colReader.GetNext(); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - BOOST_REQUIRE(rawReader.ReadInt8() == 1); -} - -void CheckRawCollection(CollectionType* colType) -{ - PortableInner writeVal1 = PortableInner(1); - PortableInner writeVal2 = PortableInner(0); - PortableInner writeVal3 = PortableInner(2); - - InteropUnpooledMemory mem(1024); - - InteropOutputStream out(&mem); - PortableWriterImpl writer(&out, NULL); - PortableRawWriter rawWriter(&writer); - - PortableCollectionWriter colWriter = colType ? - rawWriter.WriteCollection(*colType) : rawWriter.WriteCollection(); - - colWriter.Write(writeVal1); - colWriter.Write(writeVal2); - colWriter.Write(writeVal3); - - CheckRawWritesRestricted(rawWriter); - - colWriter.Close(); - - rawWriter.WriteInt8(1); - - try - { - colWriter.Write(1); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - colWriter.Close(); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - out.Synchronize(); - - InteropInputStream in(&mem); - PortableReaderImpl reader(&in); - PortableRawReader rawReader(&reader); - - PortableCollectionReader colReader = rawReader.ReadCollection(); - - CheckRawReadsRestricted(rawReader); - - if (colType) - BOOST_REQUIRE(colReader.GetType() == *colType); - else - BOOST_REQUIRE(colReader.GetType() == IGNITE_COLLECTION_UNDEFINED); - - BOOST_REQUIRE(colReader.GetSize() == 3); - BOOST_REQUIRE(!colReader.IsNull()); - - BOOST_REQUIRE(colReader.HasNext()); - BOOST_REQUIRE(colReader.GetNext().GetValue() == writeVal1.GetValue()); - - BOOST_REQUIRE(colReader.HasNext()); - BOOST_REQUIRE(colReader.GetNext().GetValue() == writeVal2.GetValue()); - - BOOST_REQUIRE(colReader.HasNext()); - BOOST_REQUIRE(colReader.GetNext().GetValue() == writeVal3.GetValue()); - - BOOST_REQUIRE(!colReader.HasNext()); - - try - { - colReader.GetNext(); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - BOOST_REQUIRE(rawReader.ReadInt8() == 1); -} - -void CheckRawCollectionIterators(CollectionType* colType) -{ - typedef std::vector PortableInnerVector; - - PortableInnerVector writeValues; - writeValues.push_back(1); - writeValues.push_back(0); - writeValues.push_back(2); - - InteropUnpooledMemory mem(1024); - - InteropOutputStream out(&mem); - PortableWriterImpl writer(&out, NULL); - PortableRawWriter rawWriter(&writer); - - if (colType) - rawWriter.WriteCollection(writeValues.begin(), writeValues.end(), *colType); - else - rawWriter.WriteCollection(writeValues.begin(), writeValues.end()); - - rawWriter.WriteInt8(1); - - out.Synchronize(); - - InteropInputStream in(&mem); - PortableReaderImpl reader(&in); - PortableRawReader rawReader(&reader); - - int32_t collectionSize = rawReader.ReadCollectionSize(); - BOOST_REQUIRE(collectionSize == writeValues.size()); - - if (colType) - BOOST_REQUIRE(rawReader.ReadCollectionType() == *colType); - else - BOOST_REQUIRE(rawReader.ReadCollectionType() == IGNITE_COLLECTION_UNDEFINED); - - PortableInnerVector readValues(collectionSize); - - int32_t elementsRead = rawReader.ReadCollection(readValues.begin()); - - BOOST_REQUIRE(elementsRead == 3); - - BOOST_REQUIRE(readValues[0].GetValue() == writeValues[0].GetValue()); - BOOST_REQUIRE(readValues[1].GetValue() == writeValues[1].GetValue()); - BOOST_REQUIRE(readValues[2].GetValue() == writeValues[2].GetValue()); - - BOOST_REQUIRE(rawReader.ReadInt8() == 1); -} - -void CheckRawMapEmpty(MapType* mapType) -{ - InteropUnpooledMemory mem(1024); - - InteropOutputStream out(&mem); - PortableWriterImpl writer(&out, NULL); - PortableRawWriter rawWriter(&writer); - - PortableMapWriter mapWriter = mapType ? - rawWriter.WriteMap(*mapType) : rawWriter.WriteMap(); - - CheckRawWritesRestricted(rawWriter); - - mapWriter.Close(); - - rawWriter.WriteInt8(1); - - try - { - mapWriter.Write(1, PortableInner(1)); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - mapWriter.Close(); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - out.Synchronize(); - - InteropInputStream in(&mem); - PortableReaderImpl reader(&in); - PortableRawReader rawReader(&reader); - - PortableMapReader mapReader = rawReader.ReadMap(); - - if (mapType) - BOOST_REQUIRE(mapReader.GetType() == *mapType); - else - BOOST_REQUIRE(mapReader.GetType() == IGNITE_MAP_UNDEFINED); - - BOOST_REQUIRE(mapReader.GetSize() == 0); - BOOST_REQUIRE(!mapReader.HasNext()); - BOOST_REQUIRE(!mapReader.IsNull()); - - try - { - int8_t key; - PortableInner val; - - mapReader.GetNext(&key, &val); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - BOOST_REQUIRE(rawReader.ReadInt8() == 1); -} - -void CheckRawMap(MapType* mapType) -{ - PortableInner writeVal1 = PortableInner(1); - PortableInner writeVal2 = PortableInner(0); - PortableInner writeVal3 = PortableInner(2); - - InteropUnpooledMemory mem(1024); - - InteropOutputStream out(&mem); - PortableWriterImpl writer(&out, NULL); - PortableRawWriter rawWriter(&writer); - - PortableMapWriter mapWriter = mapType ? - rawWriter.WriteMap(*mapType) : rawWriter.WriteMap(); - - mapWriter.Write(1, writeVal1); - mapWriter.Write(2, writeVal2); - mapWriter.Write(3, writeVal3); - - CheckRawWritesRestricted(rawWriter); - - mapWriter.Close(); - - rawWriter.WriteInt8(1); - - try - { - mapWriter.Write(4, PortableInner(4)); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - mapWriter.Close(); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - out.Synchronize(); - - InteropInputStream in(&mem); - PortableReaderImpl reader(&in); - PortableRawReader rawReader(&reader); - - PortableMapReader mapReader = rawReader.ReadMap(); - - CheckRawReadsRestricted(rawReader); - - if (mapType) - BOOST_REQUIRE(mapReader.GetType() == *mapType); - else - BOOST_REQUIRE(mapReader.GetType() == IGNITE_MAP_UNDEFINED); - - BOOST_REQUIRE(mapReader.GetSize() == 3); - BOOST_REQUIRE(!mapReader.IsNull()); - - int8_t key; - PortableInner val; - - BOOST_REQUIRE(mapReader.HasNext()); - - mapReader.GetNext(&key, &val); - BOOST_REQUIRE(key == 1); - BOOST_REQUIRE(val.GetValue() == writeVal1.GetValue()); - - mapReader.GetNext(&key, &val); - BOOST_REQUIRE(key == 2); - BOOST_REQUIRE(val.GetValue() == writeVal2.GetValue()); - - mapReader.GetNext(&key, &val); - BOOST_REQUIRE(key == 3); - BOOST_REQUIRE(val.GetValue() == writeVal3.GetValue()); - - BOOST_REQUIRE(!mapReader.HasNext()); - - try - { - mapReader.GetNext(&key, &val); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - BOOST_REQUIRE(rawReader.ReadInt8() == 1); -} - -BOOST_AUTO_TEST_SUITE(PortableReaderWriterRawTestSuite) - -BOOST_AUTO_TEST_CASE(TestPrimitiveInt8) -{ - CheckRawPrimitive(1); -} - -BOOST_AUTO_TEST_CASE(TestPrimitiveBool) -{ - CheckRawPrimitive(true); -} - -BOOST_AUTO_TEST_CASE(TestPrimitiveInt16) -{ - CheckRawPrimitive(1); -} - -BOOST_AUTO_TEST_CASE(TestPrimitiveUInt16) -{ - CheckRawPrimitive(1); -} - -BOOST_AUTO_TEST_CASE(TestPrimitiveInt32) -{ - CheckRawPrimitive(1); -} - -BOOST_AUTO_TEST_CASE(TestPrimitiveInt64) -{ - CheckRawPrimitive(1); -} - -BOOST_AUTO_TEST_CASE(TestPrimitiveFloat) -{ - CheckRawPrimitive(1.1f); -} - -BOOST_AUTO_TEST_CASE(TestPrimitiveDouble) -{ - CheckRawPrimitive(1.1); -} - -BOOST_AUTO_TEST_CASE(TestPrimitiveGuid) -{ - Guid val(1, 2); - - CheckRawPrimitive(val); -} - -BOOST_AUTO_TEST_CASE(TestPrimitiveArrayInt8) -{ - CheckRawPrimitiveArray(1, 2, 3); -} - -BOOST_AUTO_TEST_CASE(TestPrimitiveArrayBool) -{ - CheckRawPrimitiveArray(false, true, false); -} - -BOOST_AUTO_TEST_CASE(TestPrimitiveArrayInt16) -{ - CheckRawPrimitiveArray(1, 2, 3); -} - -BOOST_AUTO_TEST_CASE(TestPrimitiveArrayUInt16) -{ - CheckRawPrimitiveArray(1, 2, 3); -} - -BOOST_AUTO_TEST_CASE(TestPrimitiveArrayInt32) -{ - CheckRawPrimitiveArray(1, 2, 3); -} - -BOOST_AUTO_TEST_CASE(TestPrimitiveArrayInt64) -{ - CheckRawPrimitiveArray(1, 2, 3); -} - -BOOST_AUTO_TEST_CASE(TestPrimitiveArrayFloat) -{ - CheckRawPrimitiveArray(1.1f, 2.2f, 3.3f); -} - -BOOST_AUTO_TEST_CASE(TestPrimitiveArrayDouble) -{ - CheckRawPrimitiveArray(1.1, 2.2, 3.3); -} - -BOOST_AUTO_TEST_CASE(TestPrimitiveArrayGuid) -{ - Guid dflt(1, 2); - Guid val1(3, 4); - Guid val2(5, 6); - - CheckRawPrimitiveArray(dflt, val1, val2); -} - -BOOST_AUTO_TEST_CASE(TestGuidNull) -{ - InteropUnpooledMemory mem(1024); - - InteropOutputStream out(&mem); - PortableWriterImpl writer(&out, NULL); - PortableRawWriter rawWriter(&writer); - - rawWriter.WriteNull(); - - out.Synchronize(); - - InteropInputStream in(&mem); - PortableReaderImpl reader(&in); - PortableRawReader rawReader(&reader); - - Guid expVal; - Guid actualVal = rawReader.ReadGuid(); - - BOOST_REQUIRE(actualVal == expVal); -} - -BOOST_AUTO_TEST_CASE(TestString) { - InteropUnpooledMemory mem(1024); - - InteropOutputStream out(&mem); - PortableWriterImpl writer(&out, NULL); - PortableRawWriter rawWriter(&writer); - - const char* writeVal1 = "testtest"; - const char* writeVal2 = "test"; - std::string writeVal3 = writeVal1; - - rawWriter.WriteString(writeVal1); - rawWriter.WriteString(writeVal1, 4); - rawWriter.WriteString(writeVal3); - rawWriter.WriteString(NULL); - rawWriter.WriteString(NULL, 4); - - out.Synchronize(); - - InteropInputStream in(&mem); - PortableReaderImpl reader(&in); - PortableRawReader rawReader(&reader); - - char readVal1[9]; - char readVal2[5]; - - BOOST_REQUIRE(rawReader.ReadString(NULL, 0) == 8); - BOOST_REQUIRE(rawReader.ReadString(NULL, 8) == 8); - BOOST_REQUIRE(rawReader.ReadString(readVal1, 0) == 8); - BOOST_REQUIRE(rawReader.ReadString(readVal1, 4) == 8); - - BOOST_REQUIRE(rawReader.ReadString(readVal1, 9) == 8); - std::string writeVal1Str = writeVal1; - std::string readVal1Str = readVal1; - BOOST_REQUIRE(readVal1Str.compare(writeVal1Str) == 0); - - BOOST_REQUIRE(rawReader.ReadString(readVal2, 5) == 4); - std::string writeVal2Str = writeVal2; - std::string readVal2Str = readVal2; - BOOST_REQUIRE(readVal2Str.compare(writeVal2Str) == 0); - - std::string readVal3 = rawReader.ReadString(); - BOOST_REQUIRE(readVal3.compare(writeVal3) == 0); - - BOOST_REQUIRE(rawReader.ReadString(readVal1, 9) == -1); - BOOST_REQUIRE(rawReader.ReadString(readVal1, 9) == -1); -} - -BOOST_AUTO_TEST_CASE(TestStringArrayNull) -{ - InteropUnpooledMemory mem(1024); - - InteropOutputStream out(&mem); - PortableWriterImpl writer(&out, NULL); - PortableRawWriter rawWriter(&writer); - - rawWriter.WriteNull(); - rawWriter.WriteInt8(1); - - out.Synchronize(); - - InteropInputStream in(&mem); - PortableReaderImpl reader(&in); - PortableRawReader rawReader(&reader); - - PortableStringArrayReader arrReader = rawReader.ReadStringArray(); - - BOOST_REQUIRE(arrReader.GetSize() == -1); - BOOST_REQUIRE(!arrReader.HasNext()); - BOOST_REQUIRE(arrReader.IsNull()); - - try - { - char res[100]; - - arrReader.GetNext(res, 100); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - arrReader.GetNext(); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - BOOST_REQUIRE(rawReader.ReadInt8() == 1); -} - -BOOST_AUTO_TEST_CASE(TestStringArrayEmpty) -{ - InteropUnpooledMemory mem(1024); - - InteropOutputStream out(&mem); - PortableWriterImpl writer(&out, NULL); - PortableRawWriter rawWriter(&writer); - - PortableStringArrayWriter arrWriter = rawWriter.WriteStringArray(); - - CheckRawWritesRestricted(rawWriter); - - arrWriter.Close(); - - rawWriter.WriteInt8(1); - - try - { - const char* val = "test"; - - arrWriter.Write(val, 4); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - const char* val = "test"; - - arrWriter.Write(val); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - std::string val = "test"; - - arrWriter.Write(val); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - arrWriter.Close(); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - out.Synchronize(); - - InteropInputStream in(&mem); - PortableReaderImpl reader(&in); - PortableRawReader rawReader(&reader); - - PortableStringArrayReader arrReader = rawReader.ReadStringArray(); - - BOOST_REQUIRE(arrReader.GetSize() == 0); - BOOST_REQUIRE(!arrReader.HasNext()); - BOOST_REQUIRE(!arrReader.IsNull()); - - try - { - char res[100]; - - arrReader.GetNext(res, 100); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - arrReader.GetNext(); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - BOOST_REQUIRE(rawReader.ReadInt8() == 1); -} - -BOOST_AUTO_TEST_CASE(TestStringArray) -{ - const char* writeVal1 = "testtest"; - const char* writeVal2 = "test"; - std::string writeVal3 = "test2"; - - InteropUnpooledMemory mem(1024); - - InteropOutputStream out(&mem); - PortableWriterImpl writer(&out, NULL); - PortableRawWriter rawWriter(&writer); - - PortableStringArrayWriter arrWriter = rawWriter.WriteStringArray(); - - arrWriter.Write(writeVal1); - arrWriter.Write(writeVal1, 4); - arrWriter.Write(NULL); // NULL value. - arrWriter.Write(NULL, 100); // NULL value again. - arrWriter.Write(writeVal3); - - CheckRawWritesRestricted(rawWriter); - - arrWriter.Close(); - - rawWriter.WriteInt8(1); - - try - { - const char* val = "test"; - - arrWriter.Write(val, 4); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - const char* val = "test"; - - arrWriter.Write(val); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - std::string val = "test"; - - arrWriter.Write(val); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - arrWriter.Close(); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - out.Synchronize(); - - InteropInputStream in(&mem); - PortableReaderImpl reader(&in); - PortableRawReader rawReader(&reader); - - PortableStringArrayReader arrReader = rawReader.ReadStringArray(); - - CheckRawReadsRestricted(rawReader); - - BOOST_REQUIRE(arrReader.GetSize() == 5); - BOOST_REQUIRE(!arrReader.IsNull()); - - // 1. Read first value. - BOOST_REQUIRE(arrReader.HasNext()); - - char readVal1[9]; - - BOOST_REQUIRE(arrReader.GetNext(NULL, 0) == 8); - BOOST_REQUIRE(arrReader.GetNext(NULL, 8) == 8); - BOOST_REQUIRE(arrReader.GetNext(readVal1, 0) == 8); - BOOST_REQUIRE(arrReader.GetNext(readVal1, 4) == 8); - - BOOST_REQUIRE(arrReader.GetNext(readVal1, 9) == 8); - std::string writeVal1Str = writeVal1; - std::string readVal1Str = readVal1; - BOOST_REQUIRE(readVal1Str.compare(writeVal1Str) == 0); - - // 2. Read second value. - BOOST_REQUIRE(arrReader.HasNext()); - - char readVal2[5]; - - BOOST_REQUIRE(arrReader.GetNext(readVal2, 5) == 4); - std::string writeVal2Str = writeVal2; - std::string readVal2Str = readVal2; - BOOST_REQUIRE(readVal2Str.compare(writeVal2Str) == 0); - - // 3. Read NULL. - BOOST_REQUIRE(arrReader.HasNext()); - - BOOST_REQUIRE(arrReader.GetNext(readVal1, 4) == -1); - readVal1Str = readVal1; - BOOST_REQUIRE(readVal1Str.compare(writeVal1Str) == 0); - - // 4. Read NULL again, this time through another method. - BOOST_REQUIRE(arrReader.HasNext()); - - std::string readNullVal = arrReader.GetNext(); - - BOOST_REQUIRE(readNullVal.length() == 0); - - // 5. Read third value. - BOOST_REQUIRE(arrReader.HasNext()); - - std::string readVal3 = arrReader.GetNext(); - BOOST_REQUIRE(readVal3.compare(writeVal3) == 0); - - BOOST_REQUIRE(!arrReader.HasNext()); - - try - { - char res[100]; - - arrReader.GetNext(res, 100); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - arrReader.GetNext(); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - BOOST_REQUIRE(rawReader.ReadInt8() == 1); -} - -BOOST_AUTO_TEST_CASE(TestObject) -{ - PortableInner writeVal1(1); - PortableInner writeVal2(0); - - InteropUnpooledMemory mem(1024); - - InteropOutputStream out(&mem); - PortableWriterImpl writer(&out, NULL); - PortableRawWriter rawWriter(&writer); - - rawWriter.WriteObject(writeVal1); - rawWriter.WriteObject(writeVal2); - rawWriter.WriteNull(); - - out.Synchronize(); - - InteropInputStream in(&mem); - PortableReaderImpl reader(&in); - PortableRawReader rawReader(&reader); - - PortableInner readVal1 = rawReader.ReadObject(); - BOOST_REQUIRE(writeVal1.GetValue() == readVal1.GetValue()); - - PortableInner readVal2 = rawReader.ReadObject(); - BOOST_REQUIRE(writeVal2.GetValue() == readVal2.GetValue()); - - PortableInner readVal3 = rawReader.ReadObject(); - BOOST_REQUIRE(0 == readVal3.GetValue()); -} - -BOOST_AUTO_TEST_CASE(TestNestedObject) -{ - PortableOuter writeVal1(1, 2); - PortableOuter writeVal2(0, 0); - - InteropUnpooledMemory mem(1024); - - InteropOutputStream out(&mem); - PortableWriterImpl writer(&out, NULL); - PortableRawWriter rawWriter(&writer); - - rawWriter.WriteObject(writeVal1); - rawWriter.WriteObject(writeVal2); - rawWriter.WriteNull(); - - out.Synchronize(); - - InteropInputStream in(&mem); - PortableReaderImpl reader(&in); - PortableRawReader rawReader(&reader); - - PortableOuter readVal1 = rawReader.ReadObject(); - BOOST_REQUIRE(writeVal1.GetValue() == readVal1.GetValue()); - BOOST_REQUIRE(writeVal1.GetInner().GetValue() == readVal1.GetInner().GetValue()); - - PortableOuter readVal2 = rawReader.ReadObject(); - BOOST_REQUIRE(writeVal2.GetValue() == readVal2.GetValue()); - BOOST_REQUIRE(writeVal2.GetInner().GetValue() == readVal2.GetInner().GetValue()); - - PortableOuter readVal3 = rawReader.ReadObject(); - BOOST_REQUIRE(0 == readVal3.GetValue()); - BOOST_REQUIRE(0 == readVal3.GetInner().GetValue()); -} - -BOOST_AUTO_TEST_CASE(TestArrayNull) -{ - InteropUnpooledMemory mem(1024); - - InteropOutputStream out(&mem); - PortableWriterImpl writer(&out, NULL); - PortableRawWriter rawWriter(&writer); - - rawWriter.WriteNull(); - rawWriter.WriteInt8(1); - - out.Synchronize(); - - InteropInputStream in(&mem); - PortableReaderImpl reader(&in); - PortableRawReader rawReader(&reader); - - PortableArrayReader arrReader = rawReader.ReadArray(); - - BOOST_REQUIRE(arrReader.GetSize() == -1); - BOOST_REQUIRE(!arrReader.HasNext()); - BOOST_REQUIRE(arrReader.IsNull()); - - try - { - arrReader.GetNext(); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - BOOST_REQUIRE(rawReader.ReadInt8() == 1); -} - -BOOST_AUTO_TEST_CASE(TestArrayEmpty) -{ - InteropUnpooledMemory mem(1024); - - InteropOutputStream out(&mem); - PortableWriterImpl writer(&out, NULL); - PortableRawWriter rawWriter(&writer); - - PortableArrayWriter arrWriter = rawWriter.WriteArray(); - - CheckRawWritesRestricted(rawWriter); - - arrWriter.Close(); - - rawWriter.WriteInt8(1); - - try - { - arrWriter.Write(1); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - arrWriter.Close(); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - out.Synchronize(); - - InteropInputStream in(&mem); - PortableReaderImpl reader(&in); - PortableRawReader rawReader(&reader); - - PortableArrayReader arrReader = rawReader.ReadArray(); - - BOOST_REQUIRE(arrReader.GetSize() == 0); - BOOST_REQUIRE(!arrReader.HasNext()); - BOOST_REQUIRE(!arrReader.IsNull()); - - try - { - arrReader.GetNext(); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - BOOST_REQUIRE(rawReader.ReadInt8() == 1); -} - -BOOST_AUTO_TEST_CASE(TestArray) -{ - PortableInner writeVal1 = PortableInner(1); - PortableInner writeVal2 = PortableInner(0); - PortableInner writeVal3 = PortableInner(2); - - InteropUnpooledMemory mem(1024); - - InteropOutputStream out(&mem); - PortableWriterImpl writer(&out, NULL); - PortableRawWriter rawWriter(&writer); - - PortableArrayWriter arrWriter = rawWriter.WriteArray(); - - arrWriter.Write(writeVal1); - arrWriter.Write(writeVal2); - arrWriter.Write(writeVal3); - - CheckRawWritesRestricted(rawWriter); - - arrWriter.Close(); - - rawWriter.WriteInt8(1); - - try - { - arrWriter.Write(1); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - try - { - arrWriter.Close(); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - out.Synchronize(); - - InteropInputStream in(&mem); - PortableReaderImpl reader(&in); - PortableRawReader rawReader(&reader); - - PortableArrayReader arrReader = rawReader.ReadArray(); - - CheckRawReadsRestricted(rawReader); - - BOOST_REQUIRE(arrReader.GetSize() == 3); - BOOST_REQUIRE(!arrReader.IsNull()); - - BOOST_REQUIRE(arrReader.HasNext()); - BOOST_REQUIRE(arrReader.GetNext().GetValue() == writeVal1.GetValue()); - - BOOST_REQUIRE(arrReader.HasNext()); - BOOST_REQUIRE(arrReader.GetNext().GetValue() == writeVal2.GetValue()); - - BOOST_REQUIRE(arrReader.HasNext()); - BOOST_REQUIRE(arrReader.GetNext().GetValue() == writeVal3.GetValue()); - - BOOST_REQUIRE(!arrReader.HasNext()); - - try - { - arrReader.GetNext(); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - BOOST_REQUIRE(rawReader.ReadInt8() == 1); -} - -BOOST_AUTO_TEST_CASE(TestCollectionNull) -{ - InteropUnpooledMemory mem(1024); - - InteropOutputStream out(&mem); - PortableWriterImpl writer(&out, NULL); - PortableRawWriter rawWriter(&writer); - - rawWriter.WriteNull(); - rawWriter.WriteInt8(1); - - out.Synchronize(); - - InteropInputStream in(&mem); - PortableReaderImpl reader(&in); - PortableRawReader rawReader(&reader); - - PortableCollectionReader colReader = rawReader.ReadCollection(); - - BOOST_REQUIRE(colReader.GetType() == IGNITE_COLLECTION_UNDEFINED); - BOOST_REQUIRE(colReader.GetSize() == -1); - BOOST_REQUIRE(!colReader.HasNext()); - BOOST_REQUIRE(colReader.IsNull()); - - try - { - colReader.GetNext(); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - BOOST_REQUIRE(rawReader.ReadInt8() == 1); -} - -BOOST_AUTO_TEST_CASE(TestCollectionEmpty) -{ - CheckRawCollectionEmpty(NULL); -} - -BOOST_AUTO_TEST_CASE(TestCollectionEmptyTyped) -{ - CollectionType typ = IGNITE_COLLECTION_CONCURRENT_SKIP_LIST_SET; - - CheckRawCollectionEmpty(&typ); -} - -BOOST_AUTO_TEST_CASE(TestCollection) -{ - CheckRawCollection(NULL); -} - -BOOST_AUTO_TEST_CASE(TestCollectionTyped) -{ - CollectionType typ = IGNITE_COLLECTION_CONCURRENT_SKIP_LIST_SET; - - CheckRawCollection(&typ); -} - -BOOST_AUTO_TEST_CASE(TestCollectionIterators) -{ - CheckRawCollectionIterators(NULL); -} - -BOOST_AUTO_TEST_CASE(TestCollectionIteratorsTyped) -{ - CollectionType typ = IGNITE_COLLECTION_CONCURRENT_SKIP_LIST_SET; - - CheckRawCollectionIterators(&typ); -} - -BOOST_AUTO_TEST_CASE(TestMapNull) -{ - InteropUnpooledMemory mem(1024); - - InteropOutputStream out(&mem); - PortableWriterImpl writer(&out, NULL); - PortableRawWriter rawWriter(&writer); - - rawWriter.WriteNull(); - rawWriter.WriteInt8(1); - - out.Synchronize(); - - InteropInputStream in(&mem); - PortableReaderImpl reader(&in); - PortableRawReader rawReader(&reader); - - PortableMapReader mapReader = rawReader.ReadMap(); - - BOOST_REQUIRE(mapReader.GetType() == IGNITE_MAP_UNDEFINED); - BOOST_REQUIRE(mapReader.GetSize() == -1); - BOOST_REQUIRE(!mapReader.HasNext()); - BOOST_REQUIRE(mapReader.IsNull()); - - try - { - int8_t key; - PortableInner val; - - mapReader.GetNext(&key, &val); - - BOOST_FAIL("Error expected."); - } - catch (IgniteError& err) - { - BOOST_REQUIRE(err.GetCode() == IgniteError::IGNITE_ERR_PORTABLE); - } - - BOOST_REQUIRE(rawReader.ReadInt8() == 1); -} - -BOOST_AUTO_TEST_CASE(TestMapEmpty) -{ - CheckRawMapEmpty(NULL); -} - -BOOST_AUTO_TEST_CASE(TestMapEmptyTyped) -{ - MapType typ = IGNITE_MAP_CONCURRENT_HASH_MAP; - - CheckRawMapEmpty(&typ); -} - -BOOST_AUTO_TEST_CASE(TestMap) -{ - CheckRawMap(NULL); -} - -BOOST_AUTO_TEST_CASE(TestMapTyped) -{ - MapType typ = IGNITE_MAP_CONCURRENT_HASH_MAP; - - CheckRawMap(&typ); -} - -BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file