mirror of
https://github.com/oatpp/oatpp.git
synced 2025-03-31 18:30:22 +08:00
Debug loags removed, TypeTest added
This commit is contained in:
parent
0645cf258b
commit
8d4a91f97d
@ -79,11 +79,7 @@ public:
|
||||
typename Class::ObjectWrapper readFromString(const oatpp::String& str) const {
|
||||
auto type = Class::ObjectWrapper::Class::getType();
|
||||
oatpp::parser::ParsingCaret caret(str);
|
||||
auto result = oatpp::data::mapping::type::static_wrapper_cast<typename Class::ObjectWrapper::ObjectType>(read(caret, type));
|
||||
if(caret.hasError() || result.get() == nullptr ) {
|
||||
OATPP_LOGD("test", "caret->hasError '%s', %d", caret.getError(), caret.getPosition());
|
||||
}
|
||||
return result;
|
||||
return oatpp::data::mapping::type::static_wrapper_cast<typename Class::ObjectWrapper::ObjectType>(read(caret, type));
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -219,12 +219,7 @@ Deserializer::AbstractObjectWrapper Deserializer::readValue(const Type* const ty
|
||||
} else if(typeName == oatpp::data::mapping::type::__class::AbstractListMap::CLASS_NAME){
|
||||
return readListMapValue(type, caret, config);
|
||||
} else {
|
||||
OATPP_LOGD("test", "unknown type '%s'", typeName);
|
||||
OATPP_LOGD("test", "string type name '%s'", oatpp::data::mapping::type::__class::String::CLASS_NAME);
|
||||
OATPP_LOGD("test", "unknown type addr %d", typeName);
|
||||
OATPP_LOGD("test", "string type addr %d", oatpp::data::mapping::type::__class::String::CLASS_NAME);
|
||||
throw std::runtime_error("unknown type");
|
||||
//skipValue(caret);
|
||||
skipValue(caret);
|
||||
}
|
||||
|
||||
return AbstractObjectWrapper::empty();
|
||||
@ -339,8 +334,6 @@ Deserializer::AbstractObjectWrapper Deserializer::readObject(const Type* type,
|
||||
auto object = type->creator();
|
||||
const auto& fieldsMap = type->properties->getMap();
|
||||
|
||||
OATPP_LOGD("test", "fieldsMap size=%d", fieldsMap.size());
|
||||
|
||||
while (!caret.isAtChar('}') && caret.canContinue()) {
|
||||
|
||||
caret.findNotBlankChar();
|
||||
@ -351,10 +344,9 @@ Deserializer::AbstractObjectWrapper Deserializer::readObject(const Type* type,
|
||||
|
||||
auto fieldIterator = fieldsMap.find(key);
|
||||
if(fieldIterator != fieldsMap.end()){
|
||||
OATPP_LOGD("test", "field found '%s'", key.c_str());
|
||||
|
||||
caret.findNotBlankChar();
|
||||
if(!caret.canContinueAtChar(':', 1)){
|
||||
OATPP_LOGD("test", "error '%s'", ERROR_PARSER_OBJECT_SCOPE_COLON_MISSING);
|
||||
caret.setError(ERROR_PARSER_OBJECT_SCOPE_COLON_MISSING);
|
||||
return AbstractObjectWrapper::empty();
|
||||
}
|
||||
@ -362,17 +354,9 @@ Deserializer::AbstractObjectWrapper Deserializer::readObject(const Type* type,
|
||||
caret.findNotBlankChar();
|
||||
|
||||
auto field = fieldIterator->second;
|
||||
auto value = readValue(field->type, caret, config);
|
||||
if(!value){
|
||||
OATPP_LOGD("test", "value is null");
|
||||
}
|
||||
if(value.get() == nullptr) {
|
||||
OATPP_LOGD("test", "strange if not called");
|
||||
}
|
||||
field->set(object.get(), value);
|
||||
field->set(object.get(), readValue(field->type, caret, config));
|
||||
|
||||
} else if (config->allowUnknownFields) {
|
||||
OATPP_LOGD("test", "unknown field '%s'", key.c_str());
|
||||
caret.findNotBlankChar();
|
||||
if(!caret.canContinueAtChar(':', 1)){
|
||||
caret.setError(ERROR_PARSER_OBJECT_SCOPE_COLON_MISSING);
|
||||
@ -381,7 +365,6 @@ Deserializer::AbstractObjectWrapper Deserializer::readObject(const Type* type,
|
||||
caret.findNotBlankChar();
|
||||
skipValue(caret);
|
||||
} else {
|
||||
OATPP_LOGD("test", "error '%s'", ERROR_PARSER_OBJECT_SCOPE_UNKNOWN_FIELD);
|
||||
caret.setError(ERROR_PARSER_OBJECT_SCOPE_UNKNOWN_FIELD);
|
||||
return AbstractObjectWrapper::empty();
|
||||
}
|
||||
|
@ -125,13 +125,6 @@ public:
|
||||
static AbstractObjectWrapper deserialize(oatpp::parser::ParsingCaret& caret,
|
||||
const std::shared_ptr<Config>& config,
|
||||
const Type* const type) {
|
||||
|
||||
OATPP_LOGD("test", "type->name='%s'", type->name);
|
||||
OATPP_LOGD("test", "__class='%s'", oatpp::data::mapping::type::__class::AbstractObject::CLASS_NAME);
|
||||
|
||||
OATPP_LOGD("test", "type->name addr=%d", type->name);
|
||||
OATPP_LOGD("test", "__class addr=%d", oatpp::data::mapping::type::__class::AbstractObject::CLASS_NAME);
|
||||
|
||||
if(type->name == oatpp::data::mapping::type::__class::AbstractObject::CLASS_NAME){
|
||||
return readObject(type, caret, config);
|
||||
} else if(type->name == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME){
|
||||
|
110
test/core/data/mapping/type/TypeTest.cpp
Normal file
110
test/core/data/mapping/type/TypeTest.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
/***************************************************************************
|
||||
*
|
||||
* 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 "TypeTest.hpp"
|
||||
|
||||
#include "oatpp/parser/json/mapping/ObjectMapper.hpp"
|
||||
#include "oatpp/core/macro/codegen.hpp"
|
||||
|
||||
namespace oatpp { namespace test { namespace core { namespace data { namespace mapping { namespace type {
|
||||
|
||||
namespace {
|
||||
|
||||
#include OATPP_CODEGEN_BEGIN(DTO)
|
||||
|
||||
typedef oatpp::data::mapping::type::Object DTO;
|
||||
|
||||
class TestDto : public DTO {
|
||||
|
||||
DTO_INIT(TestDto, DTO)
|
||||
|
||||
DTO_FIELD(String, _string);
|
||||
DTO_FIELD(Int32, _int32);
|
||||
DTO_FIELD(Int64, _int64);
|
||||
DTO_FIELD(Float32, _float32);
|
||||
DTO_FIELD(Float64, _float64);
|
||||
DTO_FIELD(Boolean, _boolean);
|
||||
|
||||
DTO_FIELD(List<String>::ObjectWrapper, _list_string) = List<String>::createShared();
|
||||
DTO_FIELD(List<Int32>::ObjectWrapper, _list_int32) = List<Int32>::createShared();
|
||||
DTO_FIELD(List<Int64>::ObjectWrapper, _list_int64) = List<Int64>::createShared();
|
||||
DTO_FIELD(List<Float32>::ObjectWrapper, _list_float32) = List<Float32>::createShared();
|
||||
DTO_FIELD(List<Float64>::ObjectWrapper, _list_float64) = List<Float64>::createShared();
|
||||
DTO_FIELD(List<Boolean>::ObjectWrapper, _list_boolean) = List<Boolean>::createShared();
|
||||
|
||||
DTO_FIELD(TestDto::ObjectWrapper, obj1);
|
||||
|
||||
};
|
||||
|
||||
#include OATPP_CODEGEN_END(DTO)
|
||||
|
||||
}
|
||||
|
||||
bool TypeTest::onRun() {
|
||||
|
||||
auto obj = TestDto::createShared();
|
||||
|
||||
OATPP_LOGD(TAG, "type: '%s'", obj->_string.valueType->name);
|
||||
OATPP_ASSERT(obj->_string.valueType->name == oatpp::data::mapping::type::__class::String::CLASS_NAME);
|
||||
|
||||
OATPP_LOGD(TAG, "type: '%s'", obj->_int32.valueType->name);
|
||||
OATPP_ASSERT(obj->_int32.valueType->name == oatpp::data::mapping::type::__class::Int32::CLASS_NAME);
|
||||
|
||||
OATPP_LOGD(TAG, "type: '%s'", obj->_int64.valueType->name);
|
||||
OATPP_ASSERT(obj->_int64.valueType->name == oatpp::data::mapping::type::__class::Int64::CLASS_NAME);
|
||||
|
||||
OATPP_LOGD(TAG, "type: '%s'", obj->_float32.valueType->name);
|
||||
OATPP_ASSERT(obj->_float32.valueType->name == oatpp::data::mapping::type::__class::Float32::CLASS_NAME);
|
||||
|
||||
OATPP_LOGD(TAG, "type: '%s'", obj->_float64.valueType->name);
|
||||
OATPP_ASSERT(obj->_float64.valueType->name == oatpp::data::mapping::type::__class::Float64::CLASS_NAME);
|
||||
|
||||
OATPP_LOGD(TAG, "type: '%s'", obj->_boolean.valueType->name);
|
||||
OATPP_ASSERT(obj->_boolean.valueType->name == oatpp::data::mapping::type::__class::Boolean::CLASS_NAME);
|
||||
|
||||
OATPP_LOGD(TAG, "type: '%s'", obj->_list_string.valueType->name);
|
||||
OATPP_ASSERT(obj->_list_string.valueType->name == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME);
|
||||
|
||||
OATPP_LOGD(TAG, "type: '%s'", obj->_list_int32.valueType->name);
|
||||
OATPP_ASSERT(obj->_list_int32.valueType->name == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME);
|
||||
|
||||
OATPP_LOGD(TAG, "type: '%s'", obj->_list_int64.valueType->name);
|
||||
OATPP_ASSERT(obj->_list_int64.valueType->name == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME);
|
||||
|
||||
OATPP_LOGD(TAG, "type: '%s'", obj->_list_float32.valueType->name);
|
||||
OATPP_ASSERT(obj->_list_float32.valueType->name == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME);
|
||||
|
||||
OATPP_LOGD(TAG, "type: '%s'", obj->_list_float64.valueType->name);
|
||||
OATPP_ASSERT(obj->_list_float64.valueType->name == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME);
|
||||
|
||||
OATPP_LOGD(TAG, "type: '%s'", obj->_list_boolean.valueType->name);
|
||||
OATPP_ASSERT(obj->_list_boolean.valueType->name == oatpp::data::mapping::type::__class::AbstractList::CLASS_NAME);
|
||||
|
||||
OATPP_LOGD(TAG, "type: '%s'", obj->obj1.valueType->name);
|
||||
OATPP_ASSERT(obj->obj1.valueType->name == oatpp::data::mapping::type::__class::AbstractObject::CLASS_NAME);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}}}}}}
|
42
test/core/data/mapping/type/TypeTest.hpp
Normal file
42
test/core/data/mapping/type/TypeTest.hpp
Normal 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_mapping_type_TypeTest_hpp
|
||||
#define oatpp_test_core_data_mapping_type_TypeTest_hpp
|
||||
|
||||
#include "oatpp/test/UnitTest.hpp"
|
||||
|
||||
namespace oatpp { namespace test { namespace core { namespace data { namespace mapping { namespace type {
|
||||
|
||||
class TypeTest : public UnitTest{
|
||||
public:
|
||||
|
||||
TypeTest():UnitTest("TEST[core::data::mapping::type::TypeTest]"){}
|
||||
bool onRun() override;
|
||||
|
||||
};
|
||||
|
||||
}}}}}}
|
||||
|
||||
#endif /* oatpp_test_core_data_mapping_type_TypeTest_hpp */
|
Loading…
x
Reference in New Issue
Block a user