This is an automated email from the ASF dual-hosted git repository. igodwin pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/geode-native.git
The following commit(s) were added to refs/heads/develop by this push: new 09f720a GEODE-5825: Add unit tests for TcrMessageHelper (#410) 09f720a is described below commit 09f720a50cf1ddb921815b0c31e0bff0d9b00573 Author: Michael Martell <mmart...@pivotal.io> AuthorDate: Wed Dec 19 15:34:20 2018 -0800 GEODE-5825: Add unit tests for TcrMessageHelper (#410) - Using the unit test framework to handle the expected exception. - Used EXPECT_THROW instead of try/catch. Co-authored-by: Matthew Reddington <mredding...@pivotal.io> --- cppcache/integration/test/CMakeLists.txt | 1 + cppcache/integration/test/ChunkedHeaderTest.cpp | 73 +++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/cppcache/integration/test/CMakeLists.txt b/cppcache/integration/test/CMakeLists.txt index f2552ed..f371251 100644 --- a/cppcache/integration/test/CMakeLists.txt +++ b/cppcache/integration/test/CMakeLists.txt @@ -14,6 +14,7 @@ # limitations under the License. add_executable(cpp-integration-test + ChunkedHeaderTest.cpp ExampleTest.cpp RegionPutGetAllTest.cpp PdxInstanceTest.cpp diff --git a/cppcache/integration/test/ChunkedHeaderTest.cpp b/cppcache/integration/test/ChunkedHeaderTest.cpp new file mode 100644 index 0000000..767c8fc --- /dev/null +++ b/cppcache/integration/test/ChunkedHeaderTest.cpp @@ -0,0 +1,73 @@ +/* + * 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. + */ + +#include <DataInputInternal.hpp> +#include <TcrMessage.hpp> + +#include <gtest/gtest.h> + +using apache::geode::client::DataInput; +using apache::geode::client::DataInputInternal; +using apache::geode::client::DSCode; +using apache::geode::client::MessageException; +using apache::geode::client::Region; +using apache::geode::client::Serializable; +using apache::geode::client::TcrMessage; +using apache::geode::client::TcrMessageHelper; +using apache::geode::client::ThinClientBaseDM; + +namespace { +class TcrMessageTestFixture : public TcrMessage { + public: + TcrMessageTestFixture() : TcrMessage() {} + virtual ~TcrMessageTestFixture() {} +}; +} // namespace + +TEST(TcrMessageHelperTest, readChunkPartHeaderExpectsAnObject) { + TcrMessageTestFixture msg; + + uint8_t fakeBuffer[5] = {0, 0, 0, 1}; + + auto input = DataInputInternal(fakeBuffer, sizeof(fakeBuffer)); + + uint32_t partLength; + + EXPECT_THROW(TcrMessageHelper::readChunkPartHeader( + msg, input, + "TcrMessageHelperTest, readChunkPartHeaderExpectsAnObject", + partLength, 0), + MessageException); +} + +TEST(TcrMessageHelperTest, readChunkPartHeaderExceptionChunkHack) { + TcrMessageTestFixture msg; + + uint8_t fakeBuffer[] = { + 0, 0, 0, 1, 1, static_cast<uint8_t>(DSCode::JavaSerializable), + 0, 0, 0, 0, 0}; + + auto input = DataInputInternal(fakeBuffer, sizeof(fakeBuffer)); + + uint32_t partLength; + + EXPECT_EQ(TcrMessageHelper::readChunkPartHeader( + msg, input, + "TcrMessageHelperTest, readChunkPartHeaderExceptionChunkHack", + partLength, 64), + TcrMessageHelper::ChunkObjectType::EXCEPTION); +}