/*
 * Copyright (C) 2020-2021 Aloysius Indrayanto
 *
 * This file is part of the eCxx library, see LICENSE file for the license details.
 */


#include "TestUtility.h"


//
// A derivative class for testing BasicOutputWriter
//
class TestOW : public eCxx::BasicOutputWriter<TestOW> {
    public:
        inline bool write(eCxx::uint8_t value)
        {
            printf("%c", value);
            return true;
        }
};


//
// Test application
//
int main()
{
    TestOW tow;

    tow.writeStringln("Test C-String");
    tow.writeStringln( PGM_STR("Test PGM-String") );
    tow.write('\n');
    _DIVIDERLINE_DASHSTR_NL2();



    tow.writeBinStringln(
        static_cast<eCxx::uint32_t>(0b10010000101010100000111111110000),
        eCxx::Convert::NumSign::None_Minus,
        35,
        eCxx::Convert::Convert::NumPad::Zero,
        eCxx::Convert::Convert::NumFormat::Lowercase
    );
    tow.writeBinStringln(
        static_cast<eCxx::uint32_t>(0b10010000101010100000111111110000),
        eCxx::Convert::NumSign::None_Minus,
        35,
        eCxx::Convert::Convert::NumPad::Zero,
        eCxx::Convert::Convert::NumFormat::LowercaseWithPrefix
    );
    tow.writeBinStringln(
        static_cast<eCxx::uint32_t>(0b10010000101010100000111111110000),
        eCxx::Convert::NumSign::Plus_Minus,
        35,
        eCxx::Convert::Convert::NumPad::Zero,
        eCxx::Convert::Convert::NumFormat::LowercaseWithPrefix
    );
    tow.writeBinStringln(
        static_cast<eCxx::int32_t >(0b10010000101010100000111111110000),
        eCxx::Convert::NumSign::Plus_Minus,
        35,
        eCxx::Convert::Convert::NumPad::Zero,
        eCxx::Convert::Convert::NumFormat::LowercaseWithPrefix
    );
    tow.writeBinStringln(
        static_cast<eCxx::int32_t >(0b10010000101010100000111111110000),
        eCxx::Convert::NumSign::Plus_Minus,
        35,
        eCxx::Convert::Convert::NumPad::Zero,
        eCxx::Convert::Convert::NumFormat::UppercaseWithPrefix
    );
    tow.write('\n');
    _DIVIDERLINE_DASHSTR_NL2();



    tow.writeHexStringln(
        static_cast<eCxx::uint32_t>(0x90AA0FF0),
        eCxx::Convert::NumSign::None_Minus,
        12,
        eCxx::Convert::Convert::NumPad::Zero,
        eCxx::Convert::Convert::NumFormat::Lowercase
    );
    tow.writeHexStringln(
        static_cast<eCxx::uint32_t>(0xFF0AA09),
        eCxx::Convert::NumSign::None_Minus,
        12,
        eCxx::Convert::Convert::NumPad::Zero,
        eCxx::Convert::Convert::NumFormat::LowercaseWithPrefix
    );
    tow.writeHexStringln(
        static_cast<eCxx::uint32_t>(0xFF0AA09),
        eCxx::Convert::NumSign::Plus_Minus,
        12,
        eCxx::Convert::Convert::NumPad::Zero,
        eCxx::Convert::Convert::NumFormat::LowercaseWithPrefix
    );
    tow.writeHexStringln(
        static_cast<eCxx::int32_t >(0xFF0AA09),
        eCxx::Convert::NumSign::Plus_Minus,
        12,
        eCxx::Convert::Convert::NumPad::Zero,
        eCxx::Convert::Convert::NumFormat::LowercaseWithPrefix
    );
    tow.writeHexStringln(
        static_cast<eCxx::int32_t >(0xFF0AA09),
        eCxx::Convert::NumSign::Plus_Minus,
        12,
        eCxx::Convert::Convert::NumPad::Zero,
        eCxx::Convert::Convert::NumFormat::UppercaseWithPrefix
    );
    tow.write('\n');
    _DIVIDERLINE_DASHSTR_NL2();



    tow.writeStringln   ( eCxx::Bool(true)                                          );
    tow.writeBinStringln( eCxx::Bool(true),  1, eCxx::Convert::NumFormat::Lowercase );
    tow.writeDecStringln( eCxx::Bool(true)                                          );
    tow.writeHexStringln( eCxx::Bool(true),  1, eCxx::Convert::NumFormat::Lowercase );
    tow.write('\n');

    tow.writeStringln   ( eCxx::Bool(false)                                         );
    tow.writeBinStringln( eCxx::Bool(false), 1, eCxx::Convert::NumFormat::Lowercase );
    tow.writeDecStringln( eCxx::Bool(false)                                         );
    tow.writeHexStringln( eCxx::Bool(false), 1, eCxx::Convert::NumFormat::Lowercase );
    tow.write('\n');
    _DIVIDERLINE_DASHSTR_NL2();



    eCxx::uint32_t dummy;
    tow.printfString( PGM_STR("|%d| |%zd| |%p|\n"), (int) 123, (size_t) 123, &dummy);
    tow.printfString( PGM_STR("|%20p| |%-20p| |%020p| |%-020p|\n"), &dummy, &dummy, &dummy, &dummy);
    tow.write('\n');

    tow.printfString( PGM_STR("|%s| |%c|\n"), "Hello", 'A' );
    tow.printfString( PGM_STR("|%20s| |%20c|\n"), "Hello", 'A' );
    tow.printfString( PGM_STR("|%-20s| |%-20c|\n"), "Hello", 'A' );
    tow.write('\n');

    tow.printfString( PGM_STR("|%d| |%x|\n"), 12345, 12345);
    tow.printfString( PGM_STR("|%d| |%x|\n"), -12345, -12345);
    tow.write('\n');

    tow.printfString( PGM_STR("|%10d| |%010d| |%+10d| |% 10d| |%-10d|\n"), 12345, 12345, 12345, 12345, 12345);
    tow.printfString( PGM_STR("|%10d| |%010d| |%+10d| |% 10d| |%-10d|\n"), -12345, -12345, -12345, -12345, -12345);
    tow.write('\n');



    return 0;
}
