~ubuntu-branches/debian/sid/subversion/sid

« back to all changes in this revision

Viewing changes to subversion/bindings/cxxhl/tests/test_exception.cpp

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2015-08-07 21:32:47 UTC
  • mfrom: (0.2.15) (4.1.7 experimental)
  • Revision ID: package-import@ubuntu.com-20150807213247-ozyewtmgsr6tkewl
Tags: 1.9.0-1
* Upload to unstable
* New upstream release.
  + Security fixes
    - CVE-2015-3184: Mixed anonymous/authenticated path-based authz with
      httpd 2.4
    - CVE-2015-3187: svn_repos_trace_node_locations() reveals paths hidden
      by authz
* Add >= 2.7 requirement for python-all-dev Build-Depends, needed to run
  tests.
* Remove Build-Conflicts against ruby-test-unit.  (Closes: #791844)
* Remove patches/apache_module_dependency in favor of expressing the
  dependencies in authz_svn.load/dav_svn.load.
* Build-Depend on apache2-dev (>= 2.4.16) to ensure ap_some_authn_required()
  is available when building mod_authz_svn and Depend on apache2-bin (>=
  2.4.16) for runtime support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 */
21
21
 
22
22
#include <algorithm>
 
23
#include <cstdio>
23
24
#include <iomanip>
24
25
#include <ios>
25
26
#include <iostream>
26
27
 
27
28
#include "svncxxhl.hpp"
 
29
#include "../src/private.hpp"
28
30
 
29
31
#include <apr.h>
30
32
#include "svn_error.h"
31
 
 
32
 
namespace {
33
 
void trace(const svn::error::message& msg)
34
 
{
35
 
  std::cout << "    ";
36
 
  if (msg.first)
37
 
    std::cout << "test_exception: E"
38
 
              << std::setw(6) << std::setfill('0') << std::right
39
 
              << msg.first << ':' << ' ';
40
 
  std::cout << msg.second << std::endl;
41
 
}
42
 
 
43
 
void traceall(const char *message, const svn::error& err)
44
 
{
45
 
  typedef svn::error::message_list message_list;
46
 
  std::cout << message << std::endl;
47
 
  std::cout << "Traced Messages:" << std::endl;
48
 
  message_list ml = err.traced_messages();
49
 
  std::for_each(ml.begin(), ml.end(), trace);
50
 
  std::cout << "Just Messages:" << std::endl;
51
 
  ml = err.messages();
52
 
  std::for_each(ml.begin(), ml.end(), trace);
53
 
}
54
 
} // anonymous namespace
55
 
 
56
 
 
57
 
bool test_cancel()
58
 
{
59
 
  try
60
 
    {
61
 
      svn_error_t* err;
62
 
      err = svn_error_create(SVN_ERR_TEST_FAILED, NULL, "original message");
63
 
      err = svn_error_create(SVN_ERR_BASE, err, "wrapper message");
64
 
      err = svn_error_create(SVN_ERR_CANCELLED, err, NULL);
65
 
      err = svn_error_create(SVN_ERR_CANCELLED, err, NULL);
66
 
      err = svn_error_trace(err);
67
 
      svn::error::throw_svn_error(err);
68
 
    }
69
 
  catch (const svn::cancelled& err)
70
 
    {
71
 
      traceall("Caught: CANCEL", err);
72
 
      return true;
73
 
    }
74
 
  catch (const svn::error& err)
75
 
    {
76
 
      traceall("Caught: ERROR", err);
77
 
      return false;
78
 
    }
79
 
  catch (...)
80
 
    {
81
 
      return false;
82
 
    }
83
 
  return false;
84
 
}
85
 
 
86
 
int test_error()
87
 
{
88
 
  try
89
 
    {
90
 
      svn_error_t* err;
91
 
      err = svn_error_create(SVN_ERR_TEST_FAILED, NULL, "original message");
92
 
      err = svn_error_create(SVN_ERR_BASE, err, "wrapper message");
93
 
      err = svn_error_create(SVN_ERR_CANCELLED, err, NULL);
94
 
      err = svn_error_create(SVN_ERR_CANCELLED, err, NULL);
95
 
      err = svn_error_create(SVN_ERR_UNSUPPORTED_FEATURE, err, NULL);
96
 
      err = svn_error_create(SVN_ERR_UNSUPPORTED_FEATURE, err, NULL);
97
 
      err = svn_error_trace(err);
98
 
      svn::error::throw_svn_error(err);
99
 
    }
100
 
  catch (const svn::cancelled& err)
101
 
    {
102
 
      traceall("Caught: CANCEL", err);
103
 
      return false;
104
 
    }
105
 
  catch (const svn::error& err)
106
 
    {
107
 
      traceall("Caught: ERROR", err);
108
 
      return true;
109
 
    }
110
 
  catch (...)
111
 
    {
112
 
      return false;
113
 
    }
114
 
  return false;
115
 
}
116
 
 
117
 
int main()
118
 
{
119
 
  apr_initialize();
120
 
 
121
 
  const char *stat  = (test_cancel() ? "OK" : "ERROR");
122
 
  std::cerr << "test_cancel .... " << stat << std::endl;
123
 
 
124
 
  stat = (test_error() ? "OK" : "ERROR");
125
 
  std::cerr << "test_error ..... " << stat << std::endl;
126
 
 
127
 
  apr_terminate();
128
 
  return 0;
 
33
#undef TRUE
 
34
#undef FALSE
 
35
 
 
36
#include <gmock/gmock.h>
 
37
 
 
38
namespace {
 
39
svn_error_t* make_error_test_error()
 
40
{
 
41
  svn_error_t* err;
 
42
  err = svn_error_create(SVN_ERR_TEST_FAILED, NULL, "original message");
 
43
  err = svn_error_create(SVN_ERR_BASE, err, "wrapper message");
 
44
  err = svn_error_trace(err);
 
45
  err = svn_error_create(SVN_ERR_UNSUPPORTED_FEATURE, err, NULL);
 
46
  err = svn_error_create(SVN_ERR_UNSUPPORTED_FEATURE, err, NULL);
 
47
  err = svn_error_trace(err);
 
48
  return err;
 
49
}
 
50
} // anonymous namespace
 
51
 
 
52
TEST(Exceptions, CatchError)
 
53
{
 
54
  try
 
55
    {
 
56
      SVN::detail::checked_call(make_error_test_error());
 
57
    }
 
58
  catch (const SVN::Error& err)
 
59
    {
 
60
      SVN::Error::MessageList ml = err.messages();
 
61
      EXPECT_EQ(3, ml.size());
 
62
      EXPECT_EQ(SVN_ERR_UNSUPPORTED_FEATURE, ml[0].code());
 
63
      EXPECT_EQ(SVN_ERR_BASE, ml[1].code());
 
64
      EXPECT_EQ(SVN_ERR_TEST_FAILED, ml[2].code());
 
65
 
 
66
      SVN::Error::MessageList tml = err.traced_messages();
 
67
#ifdef SVN_DEBUG
 
68
      EXPECT_EQ(8, tml.size());
 
69
      EXPECT_EQ(SVN_ERR_UNSUPPORTED_FEATURE, tml[0].code());
 
70
      EXPECT_EQ(SVN_ERR_UNSUPPORTED_FEATURE, tml[1].code());
 
71
      EXPECT_EQ(SVN_ERR_UNSUPPORTED_FEATURE, tml[2].code());
 
72
      EXPECT_EQ(SVN_ERR_BASE, tml[3].code());
 
73
      EXPECT_EQ(SVN_ERR_BASE, tml[4].code());
 
74
      EXPECT_EQ(SVN_ERR_BASE, tml[5].code());
 
75
      EXPECT_EQ(SVN_ERR_TEST_FAILED, tml[6].code());
 
76
      EXPECT_EQ(SVN_ERR_TEST_FAILED, tml[7].code());
 
77
#else  // !SVN_DEBUG
 
78
      EXPECT_EQ(3, tml.size());
 
79
      EXPECT_EQ(SVN_ERR_UNSUPPORTED_FEATURE, tml[0].code());
 
80
      EXPECT_EQ(SVN_ERR_BASE, tml[1].code());
 
81
      EXPECT_EQ(SVN_ERR_TEST_FAILED, tml[2].code());
 
82
#endif // SVN_DEBUG
 
83
    }
 
84
}
 
85
 
 
86
 
 
87
namespace {
 
88
svn_error_t* make_cancel_test_error()
 
89
{
 
90
  svn_error_t* err;
 
91
  err = svn_error_create(SVN_ERR_CANCELLED, NULL, NULL);
 
92
  err = svn_error_create(SVN_ERR_CANCELLED, err, NULL);
 
93
  err = svn_error_trace(err);
 
94
  err = svn_error_create(SVN_ERR_TEST_FAILED, err, "original message");
 
95
  err = svn_error_create(SVN_ERR_BASE, err, "wrapper message");
 
96
  err = svn_error_trace(err);
 
97
  return err;
 
98
}
 
99
} // anonymous namespace
 
100
 
 
101
TEST(Exceptions, CatchCancelled)
 
102
{
 
103
  try
 
104
    {
 
105
      SVN::detail::checked_call(make_cancel_test_error());
 
106
    }
 
107
  catch (const SVN::Cancelled& err)
 
108
    {
 
109
      SVN::Error::MessageList ml = err.messages();
 
110
      EXPECT_EQ(3, ml.size());
 
111
      EXPECT_EQ(SVN_ERR_BASE, ml[0].code());
 
112
      EXPECT_EQ(SVN_ERR_TEST_FAILED, ml[1].code());
 
113
      EXPECT_EQ(SVN_ERR_CANCELLED, ml[2].code());
 
114
 
 
115
      SVN::Error::MessageList tml = err.traced_messages();
 
116
#ifdef SVN_DEBUG
 
117
      EXPECT_EQ(8, tml.size());
 
118
      EXPECT_EQ(SVN_ERR_BASE, tml[0].code());
 
119
      EXPECT_EQ(SVN_ERR_BASE, tml[1].code());
 
120
      EXPECT_EQ(SVN_ERR_BASE, tml[2].code());
 
121
      EXPECT_EQ(SVN_ERR_TEST_FAILED, tml[3].code());
 
122
      EXPECT_EQ(SVN_ERR_TEST_FAILED, tml[4].code());
 
123
      EXPECT_EQ(SVN_ERR_CANCELLED, tml[5].code());
 
124
      EXPECT_EQ(SVN_ERR_CANCELLED, tml[6].code());
 
125
      EXPECT_EQ(SVN_ERR_CANCELLED, tml[7].code());
 
126
#else  // !SVN_DEBUG
 
127
      EXPECT_EQ(3, tml.size());
 
128
      EXPECT_EQ(SVN_ERR_BASE, tml[0].code());
 
129
      EXPECT_EQ(SVN_ERR_TEST_FAILED, tml[1].code());
 
130
      EXPECT_EQ(SVN_ERR_CANCELLED, tml[2].code());
 
131
#endif // SVN_DEBUG
 
132
    }
129
133
}