DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (b66b287a2650)

VCS Links

Line Code
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
// Copyright (c) 2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/data_pack.h"

#include "base/file_path.h"
#include "base/path_service.h"
#include "base/string_piece.h"
#include "testing/gtest/include/gtest/gtest.h"

class DataPackTest : public testing::Test {
 public:
  DataPackTest() {
    PathService::Get(base::DIR_SOURCE_ROOT, &data_path_);
    data_path_ = data_path_.Append(
        FILE_PATH_LITERAL("base/data/data_pack_unittest/sample.pak"));
  }

  FilePath data_path_;
};

TEST_F(DataPackTest, Load) {
  base::DataPack pack;
  ASSERT_TRUE(pack.Load(data_path_));

  StringPiece data;
  ASSERT_TRUE(pack.Get(4, &data));
  EXPECT_EQ("this is id 4", data);
  ASSERT_TRUE(pack.Get(6, &data));
  EXPECT_EQ("this is id 6", data);

  // Try reading zero-length data blobs, just in case.
  ASSERT_TRUE(pack.Get(1, &data));
  EXPECT_EQ(0U, data.length());
  ASSERT_TRUE(pack.Get(10, &data));
  EXPECT_EQ(0U, data.length());

  // Try looking up an invalid key.
  ASSERT_FALSE(pack.Get(140, &data));
}