Repository: oatpp/oatpp
File: test/oatpp/core/data/stream/BufferStreamTest.cpp (C++)

Code before:
#include "oatpp/core/utils/Binary.hpp"

namespace oatpp { namespace test { namespace core { namespace data { namespace stream {

void BufferStreamTest::onRun() {

  typedef oatpp::data::stream::BufferOutputStream BufferOutputStream;

  {
    BufferOutputStream stream;

    stream  << "int=" << 1 << ", float=" << 1.1 << ", "
            << "bool=" << true << " or " << false;

    OATPP_LOGV(TAG, "str='%s'", stream.toString()->c_str());

    stream.setCurrentPosition(0);
    stream << 101;
    OATPP_ASSERT(stream.toString() == oatpp::utils::conversion::int32ToStr(101));

    stream.setCurrentPosition(0);
    stream << static_cast<v_float32>(101.1);
    OATPP_ASSERT(stream.toString() == oatpp::utils::conversion::float32ToStr(101.1f));

    stream.setCurrentPosition(0);
    stream << 101.1;
    OATPP_ASSERT(stream.toString() == oatpp::utils::conversion::float64ToStr(101.1));

    stream.setCurrentPosition(0);
    stream << true;
    OATPP_ASSERT(stream.toString() == "true");

    stream.setCurrentPosition(0);
    stream << false;
    OATPP_ASSERT(stream.toString() == "false");

    stream.setCurrentPosition(0);
    stream << oatpp::String("oat++");
    OATPP_ASSERT(stream.toString() == "oat++");

    stream.setCurrentPosition(0);
    stream << oatpp::Int8(8);
    OATPP_ASSERT(stream.toString() == oatpp::utils::conversion::int32ToStr(8));

    stream.setCurrentPosition(0);
    stream << oatpp::Int16(16);
    OATPP_ASSERT(stream.toString() == oatpp::utils::conversion::int32ToStr(16));

    stream.setCurrentPosition(0);
    stream << oatpp::Int32(32);
    OATPP_ASSERT(stream.toString() == oatpp::utils::conversion::int32ToStr(32));

Review comment (refactor):
Please do not remove this explicit type cast.
It may be run on a different platform where ex.: FP literal type is float32 by default

Code after:
#include "oatpp/core/utils/Binary.hpp"

namespace oatpp { namespace test { namespace core { namespace data { namespace stream {

void BufferStreamTest::onRun() {

  typedef oatpp::data::stream::BufferOutputStream BufferOutputStream;

  {
    BufferOutputStream stream;

    stream  << "int=" << 1 << ", float=" << 1.1 << ", "
            << "bool=" << true << " or " << false;

    OATPP_LOGV(TAG, "str='%s'", stream.toString()->c_str());

    stream.setCurrentPosition(0);
    stream << 101;
    OATPP_ASSERT(stream.toString() == oatpp::utils::conversion::int32ToStr(101));

    stream.setCurrentPosition(0);
    stream << static_cast<v_float32>(101.1);
    OATPP_ASSERT(stream.toString() == oatpp::utils::conversion::float32ToStr(101.1f));

    stream.setCurrentPosition(0);
    stream << static_cast<v_float64>(101.1);
    OATPP_ASSERT(stream.toString() == oatpp::utils::conversion::float64ToStr(101.1));

    stream.setCurrentPosition(0);
    stream << true;
    OATPP_ASSERT(stream.toString() == "true");

    stream.setCurrentPosition(0);
    stream << false;
    OATPP_ASSERT(stream.toString() == "false");

    stream.setCurrentPosition(0);
    stream << oatpp::String("oat++");
    OATPP_ASSERT(stream.toString() == "oat++");

    stream.setCurrentPosition(0);
    stream << oatpp::Int8(8);
    OATPP_ASSERT(stream.toString() == oatpp::utils::conversion::int32ToStr(8));

    stream.setCurrentPosition(0);
    stream << oatpp::Int16(16);
    OATPP_ASSERT(stream.toString() == oatpp::utils::conversion::int32ToStr(16));

    stream.setCurrentPosition(0);
    stream << oatpp::Int32(32);
    OATPP_ASSERT(stream.toString() == oatpp::utils::conversion::int32ToStr(32));