aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/testing
diff options
context:
space:
mode:
authorpsushin <psushin@yandex-team.ru>2022-02-10 16:49:19 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:19 +0300
commit4ba0e0cae125e5faa4b5664a88c54ab6af93ea4d (patch)
tree1c00333319988270b78d83715b1e56fddfa7028e /library/cpp/testing
parent7622df751aca736b9e1e20015e6787d5a65643b0 (diff)
downloadydb-4ba0e0cae125e5faa4b5664a88c54ab6af93ea4d.tar.gz
Restoring authorship annotation for <psushin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/testing')
-rw-r--r--library/cpp/testing/common/probe.h44
-rw-r--r--library/cpp/testing/gtest_extensions/probe.h42
2 files changed, 43 insertions, 43 deletions
diff --git a/library/cpp/testing/common/probe.h b/library/cpp/testing/common/probe.h
index 19910979b5..30090a85a1 100644
--- a/library/cpp/testing/common/probe.h
+++ b/library/cpp/testing/common/probe.h
@@ -1,13 +1,13 @@
-#pragma once
-
+#pragma once
+
#include <util/system/yassert.h>
namespace NTesting {
////////////////////////////////////////////////////////////////////////////////
-
+
// Below there is a serie of probe classes for testing construction/destruction copying/moving of class.
// for examples see tests in probe_ut.cpp
-
+
struct TProbeState {
int Constructors = 0;
int Destructors = 0;
@@ -17,44 +17,44 @@ namespace NTesting {
int MoveConstructors = 0;
int MoveAssignments = 0;
int Touches = 0;
-
+
TProbeState() = default;
-
+
void Reset() {
*this = TProbeState{};
}
};
-
+
// Used for probing the number of copies that occur if a type must be coerced.
class TCoercibleToProbe {
public:
TProbeState* State;
TProbeState* ShadowState;
-
+
public:
explicit TCoercibleToProbe(TProbeState* state)
: State(state)
, ShadowState(state)
{}
-
+
private:
TCoercibleToProbe(const TCoercibleToProbe&);
TCoercibleToProbe(TCoercibleToProbe&&);
TCoercibleToProbe& operator=(const TCoercibleToProbe&);
TCoercibleToProbe& operator=(TCoercibleToProbe&&);
};
-
+
// Used for probing the number of copies in an argument.
class TProbe {
public:
TProbeState* State;
TProbeState* ShadowState;
-
+
public:
static TProbe ExplicitlyCreateInvalidProbe() {
return TProbe();
}
-
+
explicit TProbe(TProbeState* state)
: State(state)
, ShadowState(state)
@@ -62,7 +62,7 @@ namespace NTesting {
Y_ASSERT(State);
++State->Constructors;
}
-
+
~TProbe() {
if (State) {
++State->Destructors;
@@ -71,7 +71,7 @@ namespace NTesting {
++ShadowState->ShadowDestructors;
}
}
-
+
TProbe(const TProbe& other)
: State(other.State)
, ShadowState(other.ShadowState)
@@ -79,7 +79,7 @@ namespace NTesting {
Y_ASSERT(State);
++State->CopyConstructors;
}
-
+
TProbe(TProbe&& other)
: State(other.State)
, ShadowState(other.ShadowState)
@@ -88,14 +88,14 @@ namespace NTesting {
other.State = nullptr;
++State->MoveConstructors;
}
-
+
TProbe(const TCoercibleToProbe& other)
: State(other.State)
, ShadowState(other.ShadowState)
{
Y_ASSERT(State);
++State->CopyConstructors;
- }
+ }
TProbe(TCoercibleToProbe&& other)
: State(other.State)
@@ -105,7 +105,7 @@ namespace NTesting {
other.State = nullptr;
++State->MoveConstructors;
}
-
+
TProbe& operator=(const TProbe& other) {
State = other.State;
ShadowState = other.ShadowState;
@@ -113,7 +113,7 @@ namespace NTesting {
++State->CopyAssignments;
return *this;
}
-
+
TProbe& operator=(TProbe&& other) {
State = other.State;
ShadowState = other.ShadowState;
@@ -122,16 +122,16 @@ namespace NTesting {
++State->MoveAssignments;
return *this;
}
-
+
void Touch() const {
Y_ASSERT(State);
++State->Touches;
}
-
+
bool IsValid() const {
return nullptr != State;
}
-
+
private:
TProbe()
: State(nullptr)
diff --git a/library/cpp/testing/gtest_extensions/probe.h b/library/cpp/testing/gtest_extensions/probe.h
index 7d1fee83d3..0313cd0f98 100644
--- a/library/cpp/testing/gtest_extensions/probe.h
+++ b/library/cpp/testing/gtest_extensions/probe.h
@@ -1,58 +1,58 @@
-#pragma once
-
+#pragma once
+
#include <util/system/yassert.h>
#include <library/cpp/testing/common/probe.h>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
-
+
namespace testing {
using NTesting::TProbe;
using NTesting::TProbeState;
using NTesting::TCoercibleToProbe;
-
+
// A helper functor which extracts from probe-like objectss their state.
struct TProbableTraits {
static const TProbeState& ExtractState(const TProbeState& probe) {
return probe;
}
-
+
static const TProbeState& ExtractState(const TProbeState* probe) {
return *probe;
}
-
+
static const TProbeState& ExtractState(const TProbe& probe) {
return *probe.State;
}
-
+
static const TProbeState& ExtractState(const TCoercibleToProbe& probe) {
return *probe.State;
}
};
-
+
void PrintTo(const TProbeState& state, ::std::ostream* os);
-
+
inline void PrintTo(const TProbe& probe, ::std::ostream* os) {
PrintTo(TProbableTraits::ExtractState(probe), os);
- }
-
+ }
+
inline void PrintTo(const TCoercibleToProbe& probe, ::std::ostream* os) {
PrintTo(TProbableTraits::ExtractState(probe), os);
- }
-
+ }
+
MATCHER(IsAlive, "is alive") {
Y_UNUSED(result_listener);
const auto& state = TProbableTraits::ExtractState(arg);
return state.Destructors < state.Constructors + state.CopyConstructors + state.CopyAssignments;
- }
-
+ }
+
MATCHER(IsDead, "is dead") {
Y_UNUSED(result_listener);
const auto& state = TProbableTraits::ExtractState(arg);
return state.Destructors == state.Constructors + state.CopyConstructors + state.CopyAssignments;
- }
-
+ }
+
MATCHER_P2(HasCopyMoveCounts, copyCount, moveCount, "" + \
PrintToString(copyCount) + " copy constructors and " + \
PrintToString(moveCount) + " move constructors were called") {
@@ -60,22 +60,22 @@ namespace testing {
const auto& state = TProbableTraits::ExtractState(arg);
return state.CopyConstructors == copyCount && state.MoveConstructors == moveCount;
}
-
+
MATCHER(NoCopies, "no copies were made") {
Y_UNUSED(result_listener);
const auto& state = TProbableTraits::ExtractState(arg);
return 0 == state.CopyConstructors && 0 == state.CopyAssignments;
}
-
+
MATCHER(NoMoves, "no moves were made") {
Y_UNUSED(result_listener);
const auto& state = TProbableTraits::ExtractState(arg);
return 0 == state.MoveConstructors && 0 == state.MoveAssignments;
}
-
+
MATCHER(NoAssignments, "no assignments were made") {
Y_UNUSED(result_listener);
const auto& state = TProbableTraits::ExtractState(arg);
return 0 == state.CopyAssignments && 0 == state.MoveAssignments;
}
-}
+}