summaryrefslogtreecommitdiff
path: root/ecos/packages/language/cxx/ustl/current/tests/bvt09.cpp
blob: 0dcf1c3b2c03813bf0baec0c8f46d703a3475696 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// This file is part of the uSTL library, an STL implementation.
//
// Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
// This file is free software, distributed under the MIT License.

#include "stdtest.h"

void TestStringStreams (void)
{
    const unsigned char magic_Char = 'c';
    const unsigned short magic_Short = 1234;
    const long magic_Int = -12345678;
    const unsigned long magic_UInt = 12345678;
    const float magic_Float = 123.45678;
    const double magic_Double = 123456789123456.789;
    const bool magic_Bool = true;

    char c = magic_Char;
    unsigned char uc = magic_Char;
    int i = magic_Int;
    short si = magic_Short;
    long li = magic_Int;
    unsigned int ui = magic_UInt;
    unsigned short usi = magic_Short;
    unsigned long uli = magic_UInt;
    float f = magic_Float;
    double d = magic_Double;
    bool bv = magic_Bool;

    ostringstream os;
    os << c << endl;
    os << uc << endl;
    os << bv << endl;
    os << i << endl;
    os << ui << endl;
    os << li << endl;
    os << uli << endl;
    os << f << endl;
    os << d << endl;
    os << si << endl;
    os << usi << endl << ends; 
    os.flush();
    cout << os.pos() << " bytes written" << endl;

    c = 0;
    uc = 0;
    bv = false;
    i = ui = li = uli = 0;
    f = 0; d = 0;
    si = usi = 0;

    istringstream is (os.str());
    is >> c;
    is >> uc;
    is >> bv;
    is >> i;
    is >> ui;
    is >> li;
    is >> uli;
    is >> f;
    is >> d;
    is >> si;
    is >> usi;

    cout << "Values:" << endl;
    cout.format ("char:    '%c'\n", static_cast<int>(c));
    cout.format ("u_char:  '%c'\n", static_cast<int>(uc));
    cout.format ("bool:    %d\n", static_cast<int>(bv));
    cout.format ("int:     %d\n", i);
    cout.format ("u_int:   %d\n", ui);
    cout.format ("long:    %ld\n", li);
    cout.format ("u_long:  %ld\n", uli);
    cout.format ("float:   %.2f\n", f);
    cout.format ("double:  %.2f\n", d);
    cout.format ("short:   %d\n", static_cast<int>(si));
    cout.format ("u_short: %d\n", static_cast<int>(usi));
    cout << endl;

    cout << "Dump:" << endl;
    cout << os.str().cdata() << endl;
    cout << endl;
}

StdBvtMain (TestStringStreams)