aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/yexception_ut.cpp
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/generic/yexception_ut.cpp
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
downloadydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'util/generic/yexception_ut.cpp')
-rw-r--r--util/generic/yexception_ut.cpp356
1 files changed, 178 insertions, 178 deletions
diff --git a/util/generic/yexception_ut.cpp b/util/generic/yexception_ut.cpp
index cb3e29fed8..9e643acf0c 100644
--- a/util/generic/yexception_ut.cpp
+++ b/util/generic/yexception_ut.cpp
@@ -1,26 +1,26 @@
-#include "yexception.h"
-
-static inline void Throw1DontMove() {
+#include "yexception.h"
+
+static inline void Throw1DontMove() {
ythrow yexception() << "blabla"; // don't move this line
-}
-
-static inline void Throw2DontMove() {
+}
+
+static inline void Throw2DontMove() {
ythrow yexception() << 1 << " qw " << 12.1; // don't move this line
-}
-
+}
+
#include <library/cpp/testing/unittest/registar.h>
-
+
#include <util/generic/algorithm.h>
#include <util/memory/tempbuf.h>
#include <util/random/mersenne.h>
#include <util/stream/output.h>
#include <util/string/subst.h>
-
+
#include "yexception_ut.h"
-#include "bt_exception.h"
+#include "bt_exception.h"
-#if defined(_MSC_VER)
- #pragma warning(disable : 4702) /*unreachable code*/
+#if defined(_MSC_VER)
+ #pragma warning(disable : 4702) /*unreachable code*/
#endif
static void CallbackFun(int i) {
@@ -28,64 +28,64 @@ static void CallbackFun(int i) {
}
static IOutputStream* OUTS = nullptr;
-
+
namespace NOuter::NInner {
void Compare10And20() {
Y_ENSURE(10 > 20);
}
}
-class TExceptionTest: public TTestBase {
- UNIT_TEST_SUITE(TExceptionTest);
- UNIT_TEST_EXCEPTION(TestException, yexception)
- UNIT_TEST_EXCEPTION(TestLineInfo, yexception)
+class TExceptionTest: public TTestBase {
+ UNIT_TEST_SUITE(TExceptionTest);
+ UNIT_TEST_EXCEPTION(TestException, yexception)
+ UNIT_TEST_EXCEPTION(TestLineInfo, yexception)
UNIT_TEST(TestCurrentExceptionMessageWhenThereisNoException)
- UNIT_TEST(TestFormat1)
- UNIT_TEST(TestRaise1)
- UNIT_TEST(TestVirtuality)
- UNIT_TEST(TestVirtualInheritance)
- UNIT_TEST(TestMixedCode)
- UNIT_TEST(TestBackTrace)
+ UNIT_TEST(TestFormat1)
+ UNIT_TEST(TestRaise1)
+ UNIT_TEST(TestVirtuality)
+ UNIT_TEST(TestVirtualInheritance)
+ UNIT_TEST(TestMixedCode)
+ UNIT_TEST(TestBackTrace)
UNIT_TEST(TestEnsureWithBackTrace1)
UNIT_TEST(TestEnsureWithBackTrace2)
- UNIT_TEST(TestRethrowAppend)
+ UNIT_TEST(TestRethrowAppend)
UNIT_TEST(TestMacroOverload)
UNIT_TEST(TestMessageCrop)
UNIT_TEST(TestTIoSystemErrorSpecialMethods)
UNIT_TEST(TestCurrentExceptionTypeNameMethod)
- UNIT_TEST_SUITE_END();
-
-private:
- inline void TestRethrowAppend() {
- try {
- try {
+ UNIT_TEST_SUITE_END();
+
+private:
+ inline void TestRethrowAppend() {
+ try {
+ try {
ythrow yexception() << "it";
- } catch (yexception& e) {
- e << "happens";
-
- throw;
- }
- } catch (...) {
+ } catch (yexception& e) {
+ e << "happens";
+
+ throw;
+ }
+ } catch (...) {
UNIT_ASSERT(CurrentExceptionMessage().Contains("ithappens"));
- }
- }
-
+ }
+ }
+
inline void TestCurrentExceptionMessageWhenThereisNoException() {
UNIT_ASSERT(CurrentExceptionMessage() == "(NO EXCEPTION)");
}
- inline void TestBackTrace() {
- try {
- ythrow TWithBackTrace<TIoSystemError>() << "test";
- } catch (...) {
+ inline void TestBackTrace() {
+ try {
+ ythrow TWithBackTrace<TIoSystemError>() << "test";
+ } catch (...) {
UNIT_ASSERT(CurrentExceptionMessage().find('\n') != TString::npos);
-
- return;
- }
-
- UNIT_ASSERT(false);
- }
-
+
+ return;
+ }
+
+ UNIT_ASSERT(false);
+ }
+
template <typename TException>
static void EnsureCurrentExceptionHasBackTrace() {
auto exceptionPtr = std::current_exception();
@@ -115,8 +115,8 @@ private:
inline void TestEnsureWithBackTrace2() {
try {
- Y_ENSURE_BT(4 > 6, "custom "
- << "message");
+ Y_ENSURE_BT(4 > 6, "custom "
+ << "message");
} catch (...) {
const TString msg = CurrentExceptionMessage();
UNIT_ASSERT(!msg.Contains("4 > 6"));
@@ -128,138 +128,138 @@ private:
UNIT_ASSERT(false);
}
- inline void TestVirtualInheritance() {
- TStringStream ss;
-
- OUTS = &ss;
-
- class TA {
- public:
- inline TA() {
- *OUTS << "A";
- }
- };
-
- class TB {
- public:
- inline TB() {
- *OUTS << "B";
- }
- };
-
- class TC: public virtual TB, public virtual TA {
- public:
- inline TC() {
- *OUTS << "C";
- }
- };
-
- class TD: public virtual TA {
- public:
- inline TD() {
- *OUTS << "D";
- }
- };
-
- class TE: public TC, public TD {
- public:
- inline TE() {
- *OUTS << "E";
- }
- };
-
- TE e;
-
- UNIT_ASSERT_EQUAL(ss.Str(), "BACDE");
- }
-
- inline void TestVirtuality() {
- try {
- ythrow TFileError() << "1";
- UNIT_ASSERT(false);
- } catch (const TIoException&) {
- } catch (...) {
- UNIT_ASSERT(false);
- }
-
- try {
- ythrow TFileError() << 1;
- UNIT_ASSERT(false);
- } catch (const TSystemError&) {
- } catch (...) {
- UNIT_ASSERT(false);
- }
-
- try {
- ythrow TFileError() << '1';
- UNIT_ASSERT(false);
- } catch (const yexception&) {
- } catch (...) {
- UNIT_ASSERT(false);
- }
-
- try {
- ythrow TFileError() << 1.0;
- UNIT_ASSERT(false);
- } catch (const TFileError&) {
- } catch (...) {
- UNIT_ASSERT(false);
- }
- }
-
- inline void TestFormat1() {
- try {
- throw yexception() << 1 << " qw " << 12.1;
- UNIT_ASSERT(false);
- } catch (...) {
+ inline void TestVirtualInheritance() {
+ TStringStream ss;
+
+ OUTS = &ss;
+
+ class TA {
+ public:
+ inline TA() {
+ *OUTS << "A";
+ }
+ };
+
+ class TB {
+ public:
+ inline TB() {
+ *OUTS << "B";
+ }
+ };
+
+ class TC: public virtual TB, public virtual TA {
+ public:
+ inline TC() {
+ *OUTS << "C";
+ }
+ };
+
+ class TD: public virtual TA {
+ public:
+ inline TD() {
+ *OUTS << "D";
+ }
+ };
+
+ class TE: public TC, public TD {
+ public:
+ inline TE() {
+ *OUTS << "E";
+ }
+ };
+
+ TE e;
+
+ UNIT_ASSERT_EQUAL(ss.Str(), "BACDE");
+ }
+
+ inline void TestVirtuality() {
+ try {
+ ythrow TFileError() << "1";
+ UNIT_ASSERT(false);
+ } catch (const TIoException&) {
+ } catch (...) {
+ UNIT_ASSERT(false);
+ }
+
+ try {
+ ythrow TFileError() << 1;
+ UNIT_ASSERT(false);
+ } catch (const TSystemError&) {
+ } catch (...) {
+ UNIT_ASSERT(false);
+ }
+
+ try {
+ ythrow TFileError() << '1';
+ UNIT_ASSERT(false);
+ } catch (const yexception&) {
+ } catch (...) {
+ UNIT_ASSERT(false);
+ }
+
+ try {
+ ythrow TFileError() << 1.0;
+ UNIT_ASSERT(false);
+ } catch (const TFileError&) {
+ } catch (...) {
+ UNIT_ASSERT(false);
+ }
+ }
+
+ inline void TestFormat1() {
+ try {
+ throw yexception() << 1 << " qw " << 12.1;
+ UNIT_ASSERT(false);
+ } catch (...) {
const TString err = CurrentExceptionMessage();
-
- UNIT_ASSERT(err.Contains("1 qw 12.1"));
- }
- }
-
+
+ UNIT_ASSERT(err.Contains("1 qw 12.1"));
+ }
+ }
+
static inline void CheckCurrentExceptionContains(const char* message) {
TString err = CurrentExceptionMessage();
SubstGlobal(err, '\\', '/'); // remove backslashes from path in message
UNIT_ASSERT(err.Contains(message));
}
- inline void TestRaise1() {
- try {
- Throw2DontMove();
- UNIT_ASSERT(false);
- } catch (...) {
+ inline void TestRaise1() {
+ try {
+ Throw2DontMove();
+ UNIT_ASSERT(false);
+ } catch (...) {
CheckCurrentExceptionContains("util/generic/yexception_ut.cpp:8: 1 qw 12.1");
- }
- }
-
- inline void TestException() {
- ythrow yexception() << "blablabla";
- }
-
- inline void TestLineInfo() {
- try {
- Throw1DontMove();
+ }
+ }
+
+ inline void TestException() {
+ ythrow yexception() << "blablabla";
+ }
+
+ inline void TestLineInfo() {
+ try {
+ Throw1DontMove();
UNIT_ASSERT(false);
- } catch (...) {
+ } catch (...) {
CheckCurrentExceptionContains("util/generic/yexception_ut.cpp:4: blabla");
-
- throw;
+
+ throw;
+ }
+ }
+
+ //! tests propagation of an exception through C code
+ //! @note on some platforms, for example GCC on 32-bit Linux without -fexceptions option,
+ //! throwing an exception from a C++ callback through C code aborts program
+ inline void TestMixedCode() {
+ const int N = 26082009;
+ try {
+ TestCallback(&CallbackFun, N);
+ UNIT_ASSERT(false);
+ } catch (int i) {
+ UNIT_ASSERT_VALUES_EQUAL(i, N);
}
- }
-
- //! tests propagation of an exception through C code
- //! @note on some platforms, for example GCC on 32-bit Linux without -fexceptions option,
- //! throwing an exception from a C++ callback through C code aborts program
- inline void TestMixedCode() {
- const int N = 26082009;
- try {
- TestCallback(&CallbackFun, N);
- UNIT_ASSERT(false);
- } catch (int i) {
- UNIT_ASSERT_VALUES_EQUAL(i, N);
- }
- }
+ }
void TestMacroOverload() {
try {
@@ -347,7 +347,7 @@ private:
}
}
//Test when the caught exception is rethrown with throw; .
- //This test is different from the previous one because of the interaction with cxxabi specifics.
+ //This test is different from the previous one because of the interaction with cxxabi specifics.
try {
throw std::bad_alloc();
} catch (...) {
@@ -387,6 +387,6 @@ private:
}
}
}
-};
-
-UNIT_TEST_SUITE_REGISTRATION(TExceptionTest);
+};
+
+UNIT_TEST_SUITE_REGISTRATION(TExceptionTest);