MCPcopy Create free account
hub / github.com/catboost/catboost / TestSharedPtrDowncast

Method TestSharedPtrDowncast

util/generic/ptr_ut.cpp:862–940  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

860};
861
862void TPointerTest::TestSharedPtrDowncast() {
863 {
864 NTesting::TProbeState probeState = {};
865
866 {
867 TSimpleSharedPtr<TVirtualProbe> base = MakeSimpleShared<TDerivedProbe>(&probeState);
868 UNIT_ASSERT_VALUES_EQUAL(probeState.Constructors, 1);
869
870 {
871 auto derived = base.As<TDerivedProbe>();
872 UNIT_ASSERT_VALUES_EQUAL(probeState.Constructors, 1);
873
874 UNIT_ASSERT_VALUES_EQUAL(base.Get(), derived.Get());
875 UNIT_ASSERT_VALUES_EQUAL(base.ReferenceCounter(), derived.ReferenceCounter());
876
877 UNIT_ASSERT_VALUES_EQUAL(base.RefCount(), 2l);
878 UNIT_ASSERT_VALUES_EQUAL(derived.RefCount(), 2l);
879 }
880
881 UNIT_ASSERT_VALUES_EQUAL(probeState.Destructors, 0);
882 }
883
884 UNIT_ASSERT_VALUES_EQUAL(probeState.Destructors, 1);
885 }
886 {
887 NTesting::TProbeState probeState = {};
888
889 {
890 TSimpleSharedPtr<TVirtualProbe> base = MakeSimpleShared<TDerivedProbe>(&probeState);
891 UNIT_ASSERT_VALUES_EQUAL(probeState.Constructors, 1);
892
893 auto derived = std::move(base).As<TDerivedProbe>();
894 UNIT_ASSERT_VALUES_EQUAL(probeState.Constructors, 1);
895 UNIT_ASSERT_VALUES_EQUAL(probeState.CopyConstructors, 0);
896 UNIT_ASSERT_VALUES_EQUAL(probeState.Destructors, 0);
897 }
898
899 UNIT_ASSERT_VALUES_EQUAL(probeState.Destructors, 1);
900 }
901 {
902 NTesting::TProbeState probeState = {};
903
904 {
905 TSimpleSharedPtr<TVirtualProbe> base = MakeSimpleShared<TDerivedProbe>(&probeState);
906 UNIT_ASSERT_VALUES_EQUAL(probeState.Constructors, 1);
907
908 {
909 auto derivedSibling = base.As<TDerivedProbeSibling>();
910 UNIT_ASSERT_VALUES_EQUAL(probeState.Constructors, 1);
911
912 UNIT_ASSERT_VALUES_EQUAL(derivedSibling.Get(), nullptr);
913 UNIT_ASSERT_VALUES_UNEQUAL(base.ReferenceCounter(), derivedSibling.ReferenceCounter());
914
915 UNIT_ASSERT_VALUES_EQUAL(base.RefCount(), 1l);
916 UNIT_ASSERT_VALUES_EQUAL(derivedSibling.RefCount(), 0l);
917 }
918
919 UNIT_ASSERT_VALUES_EQUAL(probeState.Destructors, 0);

Callers

nothing calls this directly

Calls 4

ReferenceCounterMethod · 0.80
moveFunction · 0.50
GetMethod · 0.45
RefCountMethod · 0.45

Tested by

no test coverage detected