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

Method TestCopyOnWritePtr2

util/generic/ptr_ut.cpp:492–537  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

490};
491
492void TPointerTest::TestCopyOnWritePtr2() {
493 using TPtr = TCowPtr<TIntrusivePtr<X>>;
494 TPtr p1;
495 UNIT_ASSERT(!p1.Shared());
496
497 p1.Reset(new X(123));
498 UNIT_ASSERT(!p1.Shared());
499
500 {
501 TPtr pTmp = p1;
502
503 UNIT_ASSERT(p1.Shared());
504 UNIT_ASSERT(pTmp.Shared());
505 UNIT_ASSERT_EQUAL(p1.Get(), pTmp.Get());
506 }
507
508 UNIT_ASSERT(!p1.Shared());
509
510 TPtr p2 = p1;
511 TPtr p3;
512 p3 = p2;
513
514 UNIT_ASSERT(p2.Shared());
515 UNIT_ASSERT(p3.Shared());
516 UNIT_ASSERT_EQUAL(p1.Get(), p2.Get());
517 UNIT_ASSERT_EQUAL(p1.Get(), p3.Get());
518
519 p1.Mutable()->V = 456;
520
521 UNIT_ASSERT(!p1.Shared());
522 UNIT_ASSERT(p2.Shared());
523 UNIT_ASSERT(p3.Shared());
524 UNIT_ASSERT_EQUAL(p1->V, 456);
525 UNIT_ASSERT_EQUAL(p2->V, 123);
526 UNIT_ASSERT_EQUAL(p3->V, 123);
527 UNIT_ASSERT_UNEQUAL(p1.Get(), p2.Get());
528 UNIT_ASSERT_EQUAL(p2.Get(), p3.Get());
529
530 p2.Mutable();
531
532 UNIT_ASSERT(!p2.Shared());
533 UNIT_ASSERT(!p3.Shared());
534 UNIT_ASSERT_EQUAL(p2->V, 123);
535 UNIT_ASSERT_EQUAL(p3->V, 123);
536 UNIT_ASSERT_UNEQUAL(p2.Get(), p3.Get());
537}
538
539namespace {
540 template <class TFrom, class TTo>

Callers

nothing calls this directly

Calls 4

SharedMethod · 0.80
ResetMethod · 0.45
GetMethod · 0.45
MutableMethod · 0.45

Tested by

no test coverage detected