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

Method TestCopyOnWritePtr1

util/generic/ptr_ut.cpp:436–481  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

434}
435
436void TPointerTest::TestCopyOnWritePtr1() {
437 using TPtr = TCowPtr<TSimpleSharedPtr<int>>;
438 TPtr p1;
439 UNIT_ASSERT(!p1.Shared());
440
441 p1.Reset(new int(123));
442 UNIT_ASSERT(!p1.Shared());
443
444 {
445 TPtr pTmp = p1;
446
447 UNIT_ASSERT(p1.Shared());
448 UNIT_ASSERT(pTmp.Shared());
449 UNIT_ASSERT_EQUAL(p1.Get(), pTmp.Get());
450 }
451
452 UNIT_ASSERT(!p1.Shared());
453
454 TPtr p2 = p1;
455 TPtr p3;
456 p3 = p2;
457
458 UNIT_ASSERT(p2.Shared());
459 UNIT_ASSERT(p3.Shared());
460 UNIT_ASSERT_EQUAL(p1.Get(), p2.Get());
461 UNIT_ASSERT_EQUAL(p1.Get(), p3.Get());
462
463 *(p1.Mutable()) = 456;
464
465 UNIT_ASSERT(!p1.Shared());
466 UNIT_ASSERT(p2.Shared());
467 UNIT_ASSERT(p3.Shared());
468 UNIT_ASSERT_EQUAL(*p1, 456);
469 UNIT_ASSERT_EQUAL(*p2, 123);
470 UNIT_ASSERT_EQUAL(*p3, 123);
471 UNIT_ASSERT_UNEQUAL(p1.Get(), p2.Get());
472 UNIT_ASSERT_EQUAL(p2.Get(), p3.Get());
473
474 p2.Mutable();
475
476 UNIT_ASSERT(!p2.Shared());
477 UNIT_ASSERT(!p3.Shared());
478 UNIT_ASSERT_EQUAL(*p2, 123);
479 UNIT_ASSERT_EQUAL(*p3, 123);
480 UNIT_ASSERT_UNEQUAL(p2.Get(), p3.Get());
481}
482
483struct X: public TSimpleRefCount<X> {
484 inline X(int v = 0)

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