~ubuntu-branches/ubuntu/wily/bombono-dvd/wily

« back to all changes in this revision

Viewing changes to src/mlib/tests/test_instantiate.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-11-04 11:46:25 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20101104114625-8xfdhvhpsm51i0nu
Tags: upstream-0.8.0
Import upstream version 0.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// mlib/tests/test_instantiate.cpp
 
3
// This file is part of Bombono DVD project.
 
4
//
 
5
// Copyright (c) 2010 Ilya Murav'jov
 
6
//
 
7
// This program is free software; you can redistribute it and/or modify
 
8
// it under the terms of the GNU General Public License as published by
 
9
// the Free Software Foundation; either version 2 of the License, or
 
10
// (at your option) any later version.
 
11
//
 
12
// This program is distributed in the hope that it will be useful,
 
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
// GNU General Public License for more details.
 
16
//
 
17
// You should have received a copy of the GNU General Public License
 
18
// along with this program; if not, write to the Free Software
 
19
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
20
// 
 
21
 
 
22
#include <mlib/tests/_pc_.h>
 
23
 
 
24
#include <mlib/format.h>
 
25
#include <mlib/regex.h>
 
26
#include <mlib/stream.h>
 
27
#include <mlib/tech.h>
 
28
 
 
29
BOOST_AUTO_TEST_CASE( TestFormat )
 
30
{
 
31
    // Boost.Format
 
32
    std::string f_str = (boost::format("writing %2%,  x=%1% : %3%-th try") % "toto" % 40.23 % 50).str();
 
33
    BOOST_CHECK( strcmp(f_str.c_str(), "writing 40.23,  x=toto : 50-th try") == 0 );
 
34
}
 
35
 
 
36
BOOST_AUTO_TEST_CASE( TestRegexWrapper )
 
37
{
 
38
    // re::search()
 
39
    re::pattern pat("([0-9]+)");
 
40
    std::string str = "x111xxx222dd333x";
 
41
 
 
42
    re::match_results what;
 
43
    int matches = 0;
 
44
    for( re::const_iterator it = str.begin(), end = str.end(); 
 
45
         re::search(it, end, what, pat);  
 
46
         it = what[1].second )
 
47
    {
 
48
        BOOST_CHECK_EQUAL( (int)what.size(), 2 );
 
49
        matches++;
 
50
        BOOST_CHECK_EQUAL( what.str(1), boost::format("%1%%1%%1%") % matches % bf::stop );
 
51
    }
 
52
    BOOST_CHECK_EQUAL( matches, 3 );
 
53
 
 
54
    // re::match()
 
55
    BOOST_CHECK( re::match("12345",  pat) );
 
56
    BOOST_CHECK( !re::match("12x45", pat) );
 
57
}
 
58
 
 
59
//typedef union
 
60
//{
 
61
//    uint16_t* sp;
 
62
//    uint32_t* wp;
 
63
//} U32P;
 
64
//
 
65
//uint32_t sa_swap_words(uint32_t arg)
 
66
//{
 
67
//    U32P in; // = { .wp = &arg };
 
68
//    in.wp = &arg;
 
69
//
 
70
//    const uint16_t hi = in.sp[0];
 
71
//    const uint16_t lo = in.sp[1];
 
72
//
 
73
//    in.sp[0] = lo;
 
74
//    in.sp[1] = hi;
 
75
//
 
76
//    return arg;
 
77
//}
 
78
//
 
79
//bool sa_is_swaped_vs_sa()
 
80
//{
 
81
//    return sa_swap_words(1) != 1;
 
82
//}
 
83
 
 
84
//BOOST_AUTO_TEST_CASE( TestStrictAliasing )
 
85
//{
 
86
//    BOOST_CHECK( sa_is_swaped_vs_sa() );
 
87
//}
 
88
 
 
89
UNUSED_FUNCTION
 
90
static bool SetTrue(bool& b)
 
91
{
 
92
    b = true;
 
93
    return true;
 
94
}
 
95
 
 
96
BOOST_AUTO_TEST_CASE( TestASSERT_UNUSED )
 
97
{
 
98
    int var1;
 
99
    UNUSED_VAR(var1); // без предупреждения!
 
100
 
 
101
    bool b1 = false;
 
102
    bool b2 = false;
 
103
 
 
104
#ifdef NDEBUG
 
105
    // ASSERT_OR_UNUSED
 
106
    // Внимание: выполняет выражение в скобках в любом случае, поэтому
 
107
    // подходит только для проверок переменных простых типов в отладке и
 
108
    // исключения неиспользуемости в релизе
 
109
    ASSERT_OR_UNUSED( b1 ); // не должно быть ошибки и предупреждения
 
110
 
 
111
    // ASSERT_OR_UNUSED_VAR
 
112
    // не выполняет первый аргумент в релизе
 
113
    ASSERT_OR_UNUSED_VAR( SetTrue(b2), b2 );
 
114
    ASSERT_RTL( !b2 );
 
115
#else
 
116
    // ASSERT_OR_UNUSED
 
117
    ASSERT_OR_UNUSED( !b1 ); // = ASSERT()
 
118
 
 
119
    // ASSERT_OR_UNUSED_VAR
 
120
    ASSERT_OR_UNUSED_VAR( SetTrue(b2), b2 );
 
121
    ASSERT_RTL( b2 );
 
122
#endif // NDEBUG
 
123
 
 
124
}
 
125