File: system_error_test.cpp

package info (click to toggle)
boost1.42 1.42.0-4
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 277,864 kB
  • ctags: 401,076
  • sloc: cpp: 1,235,659; xml: 74,142; ansic: 41,313; python: 26,756; sh: 11,840; cs: 2,118; makefile: 655; perl: 494; yacc: 456; asm: 353; csh: 6
file content (106 lines) | stat: -rw-r--r-- 3,209 bytes parent folder | download
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//  system_error_test.cpp  ---------------------------------------------------//

//  Copyright Beman Dawes 2006

//  Distributed under the Boost Software License, Version 1.0. (See accompanying
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

//  See library home page at http://www.boost.org/libs/system

//----------------------------------------------------------------------------// 

#include <boost/config/warning_disable.hpp>

#include <boost/test/minimal.hpp>
#include <boost/system/system_error.hpp>
#include <iostream>
#include <string>

#ifdef BOOST_WINDOWS_API
#include <windows.h>
#endif

using boost::system::system_error;
using boost::system::error_code;
using boost::system::system_category;
using std::string;

#define TEST(x,v,w) test(#x,x,v,w)

namespace
{
  void test( const char * desc, const system_error & ex,
    int v, const char * str )
  {
    std::cout << "test " << desc << "\n what() returns \"" << ex.what() << "\"\n";
    BOOST_CHECK( ex.code().value() == v );
    BOOST_CHECK( ex.code().category() == system_category );
# ifdef BOOST_WINDOWS_API
    LANGID language_id;
#   if !defined(__MINGW32__) && !defined(__CYGWIN__)
      language_id = ::GetUserDefaultUILanguage();
#   else
      language_id = 0x0409; // Assume US English
#   endif
    // std::cout << "GetUserDefaultUILanguage() returns " << language_id << '\n';
    if ( language_id == 0x0409 )  // English (United States)
    {
      BOOST_CHECK( std::string( ex.what() ) == str );
      if ( std::string( ex.what() ) != str )
        std::cout << "expected \"" << str << "\", but what() returned \""
          << ex.what() << "\"\n";
    }
# endif
  }

  const boost::uint_least32_t uvalue = 2u;
}

int test_main( int, char *[] )
{
  // all constructors, in the same order as they appear in the header:

  system_error c1_0( error_code(0, system_category) ); 
  system_error c1_1( error_code(1, system_category) );
  system_error c1_2u( error_code(uvalue, system_category) );

  system_error c2_0( error_code(0, system_category), string("c2_0") ); 
  system_error c2_1( error_code(1, system_category), string("c2_1") );

  system_error c3_0( error_code(0, system_category), "c3_0" ); 
  system_error c3_1( error_code(1, system_category), "c3_1" );

  system_error c4_0( 0, system_category ); 
  system_error c4_1( 1, system_category );
  system_error c4_2u( uvalue, system_category );

  system_error c5_0( 0, system_category, string("c5_0") ); 
  system_error c5_1( 1, system_category, string("c5_1") );

  system_error c6_0( 0, system_category, "c6_0" ); 
  system_error c6_1( 1, system_category, "c6_1" );

  TEST( c1_0, 0, "" );
  TEST( c1_1, 1, "Incorrect function" );
  TEST( c1_2u, 2, "The system cannot find the file specified" );

  TEST( c2_0, 0, "c2_0" );
  TEST( c2_1, 1, "c2_1: Incorrect function" );

  TEST( c3_0, 0, "c3_0" );
  TEST( c3_1, 1, "c3_1: Incorrect function" );

  TEST( c4_0, 0, "" );
  TEST( c4_1, 1, "Incorrect function" );
  TEST( c4_2u, 2, "The system cannot find the file specified" );

  TEST( c5_0, 0, "c5_0" );
  TEST( c5_1, 1, "c5_1: Incorrect function" );

  TEST( c6_0, 0, "c6_0" );
  TEST( c6_1, 1, "c6_1: Incorrect function" );

  return 0;
}