tests: Add InMemoryDataTest.

This commit is contained in:
lganzzzo 2021-10-28 02:46:03 +03:00
parent b5ef1ba022
commit 8d342e2967
5 changed files with 144 additions and 1 deletions

View File

@ -32,7 +32,7 @@ namespace oatpp { namespace data { namespace resource {
/**
* Abstract data resource
*/
class Resource {
class Resource : public oatpp::base::Countable {
public:
/**

View File

@ -41,6 +41,8 @@ add_executable(oatppAllTests
oatpp/core/data/mapping/type/VectorTest.hpp
oatpp/core/data/mapping/TypeResolverTest.cpp
oatpp/core/data/mapping/TypeResolverTest.hpp
oatpp/core/data/resource/InMemoryDataTest.cpp
oatpp/core/data/resource/InMemoryDataTest.hpp
oatpp/core/data/share/LazyStringMapTest.cpp
oatpp/core/data/share/LazyStringMapTest.hpp
oatpp/core/data/share/MemoryLabelTest.cpp

View File

@ -47,6 +47,8 @@
#include "oatpp/core/data/mapping/type/InterpretationTest.hpp"
#include "oatpp/core/data/mapping/TypeResolverTest.hpp"
#include "oatpp/core/data/resource/InMemoryDataTest.hpp"
#include "oatpp/core/data/stream/BufferStreamTest.hpp"
#include "oatpp/core/data/stream/ChunkedBufferTest.hpp"
#include "oatpp/core/data/share/LazyStringMapTest.hpp"
@ -111,6 +113,8 @@ void runTests() {
OATPP_RUN_TEST(oatpp::test::core::data::mapping::type::InterpretationTest);
OATPP_RUN_TEST(oatpp::test::core::data::mapping::TypeResolverTest);
OATPP_RUN_TEST(oatpp::test::core::data::resource::InMemoryDataTest);
OATPP_RUN_TEST(oatpp::test::async::LockTest);
OATPP_RUN_TEST(oatpp::test::parser::CaretTest);

View File

@ -0,0 +1,95 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.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.
*
***************************************************************************/
#include "InMemoryDataTest.hpp"
#include "oatpp/core/data/resource/InMemoryData.hpp"
namespace oatpp { namespace test { namespace core { namespace data { namespace resource {
void InMemoryDataTest::onRun() {
{
oatpp::data::resource::InMemoryData data;
OATPP_ASSERT(data.getKnownSize() == 0)
OATPP_ASSERT(data.getInMemoryData() == nullptr)
OATPP_ASSERT(data.getLocation() == nullptr)
}
{
oatpp::String testData = "Hello World";
oatpp::data::resource::InMemoryData data;
{
auto s = data.openOutputStream();
s->writeExactSizeDataSimple(testData->data(), testData->size());
}
OATPP_ASSERT(data.getKnownSize() == testData->size())
OATPP_ASSERT(data.getInMemoryData() == testData)
OATPP_ASSERT(data.getLocation() == nullptr)
}
{
oatpp::String testData1 = "Hello";
oatpp::String testData2 = "World";
oatpp::data::resource::InMemoryData data("data=");
{
auto s1 = data.openOutputStream();
s1->writeExactSizeDataSimple(testData1->data(), testData1->size());
auto s2 = data.openOutputStream();
s2->writeExactSizeDataSimple(testData2->data(), testData2->size());
s1.reset();
OATPP_ASSERT(data.getInMemoryData() == "data=" + testData1)
}
OATPP_ASSERT(data.getInMemoryData() == "data=" + testData2)
}
{
oatpp::String testData = "Hello";
oatpp::data::resource::InMemoryData data("data=");
auto is = data.openInputStream();
{
auto s1 = data.openOutputStream();
s1->writeExactSizeDataSimple(testData->data(), testData->size());
}
oatpp::data::stream::BufferOutputStream s;
char buffer[100];
oatpp::data::stream::transfer(is, &s, 0, buffer, 100);
OATPP_ASSERT(s.toString() == "data=")
}
}
}}}}}

View File

@ -0,0 +1,42 @@
/***************************************************************************
*
* Project _____ __ ____ _ _
* ( _ ) /__\ (_ _)_| |_ _| |_
* )(_)( /(__)\ )( (_ _)(_ _)
* (_____)(__)(__)(__) |_| |_|
*
*
* Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.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 oatpp_test_core_data_resource_InMemoryDataTest_hpp
#define oatpp_test_core_data_resource_InMemoryDataTest_hpp
#include "oatpp-test/UnitTest.hpp"
namespace oatpp { namespace test { namespace core { namespace data { namespace resource {
class InMemoryDataTest : public UnitTest{
public:
InMemoryDataTest():UnitTest("TEST[core::data::resource::type::InMemoryDataTest]"){}
void onRun() override;
};
}}}}}
#endif /* oatpp_test_core_data_resource_InMemoryDataTest_hpp */