File: CachingBlockStore2Test_Specific.cpp

package info (click to toggle)
cryfs 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 28,412 kB
  • sloc: cpp: 150,187; asm: 10,493; python: 1,455; javascript: 65; sh: 50; makefile: 17; xml: 7
file content (56 lines) | stat: -rw-r--r-- 2,231 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <gtest/gtest.h>

#include "blockstore/implementations/caching/CachingBlockStore2.h"
#include "blockstore/implementations/inmemory/InMemoryBlockStore2.h"
#include <cstddef>

using ::testing::Test;

using cpputils::Data;

using blockstore::inmemory::InMemoryBlockStore2;

using namespace blockstore::caching;

class CachingBlockStore2Test: public Test {
public:
  CachingBlockStore2Test():
      baseBlockStore(new InMemoryBlockStore2),
      blockStore(std::move(cpputils::nullcheck(std::unique_ptr<InMemoryBlockStore2>(baseBlockStore)).value()))  {
  }
    InMemoryBlockStore2 *baseBlockStore;
  CachingBlockStore2 blockStore;
};

TEST_F(CachingBlockStore2Test, PhysicalBlockSize_zerophysical) {
  EXPECT_EQ(0u, blockStore.blockSizeFromPhysicalBlockSize(0));
}

TEST_F(CachingBlockStore2Test, PhysicalBlockSize_zerovirtual) {
  auto blockId = blockStore.create(Data(0));
  blockStore.flush();
  auto base = baseBlockStore->load(blockId).value();
  EXPECT_EQ(0u, blockStore.blockSizeFromPhysicalBlockSize(base.size()));
}

TEST_F(CachingBlockStore2Test, PhysicalBlockSize_negativeboundaries) {
  // This tests that a potential if/else in blockSizeFromPhysicalBlockSize that catches negative values has the
  // correct boundary set. We test the highest value that is negative and the smallest value that is positive.
  auto blockId = blockStore.create(Data(0));
  blockStore.flush();
  auto physicalSizeForVirtualSizeZero = baseBlockStore->load(blockId).value().size();
  if (physicalSizeForVirtualSizeZero > 0) {
    EXPECT_EQ(0u, blockStore.blockSizeFromPhysicalBlockSize(physicalSizeForVirtualSizeZero - 1));
  }
  EXPECT_EQ(0u, blockStore.blockSizeFromPhysicalBlockSize(physicalSizeForVirtualSizeZero));
  EXPECT_EQ(1u, blockStore.blockSizeFromPhysicalBlockSize(physicalSizeForVirtualSizeZero + 1));
}

TEST_F(CachingBlockStore2Test, PhysicalBlockSize_positive) {
  auto blockId = blockStore.create(Data(10*1024u));
  blockStore.flush();
  auto base = baseBlockStore->load(blockId).value();
  EXPECT_EQ(10*1024u, blockStore.blockSizeFromPhysicalBlockSize(base.size()));
}

// TODO Add test cases that flushing the block store doesn't destroy things (i.e. all test cases from BlockStoreTest, but with flushes inbetween)