blob: cb13635d651a4c52b871711353e61e98510e67ac [file] [log] [blame]
// Copyright 2018 The Fuchsia 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 "peridot/bin/ledger/testing/ledger_matcher.h"
#include <lib/fidl/cpp/optional.h>
#include <lib/fsl/vmo/strings.h>
#include "gtest/gtest.h"
using testing::HasSubstr;
using testing::Not;
namespace ledger {
namespace {
TEST(LedgerMatcher, ExtendedStringViewMatcher) {
std::string foo = "hello";
convert::ExtendedStringView view(foo);
EXPECT_THAT(view, MatchesView("hello"));
EXPECT_THAT(view, MatchesView(HasSubstr("ll")));
EXPECT_THAT(view, Not(MatchesView("hello2")));
}
TEST(LedgerMatcher, BufferMatcher) {
fsl::SizedVmo size_vmo;
ASSERT_TRUE(fsl::VmoFromString("hello", &size_vmo));
fuchsia::mem::Buffer buffer = std::move(size_vmo).ToTransport();
EXPECT_THAT(buffer, MatchesBuffer("hello"));
EXPECT_THAT(buffer, MatchesBuffer(HasSubstr("ll")));
EXPECT_THAT(buffer, Not(MatchesBuffer("hello2")));
}
TEST(LedgerMatcher, EntryMatcher) {
fsl::SizedVmo size_vmo;
ASSERT_TRUE(fsl::VmoFromString("hello", &size_vmo));
fuchsia::mem::Buffer buffer = std::move(size_vmo).ToTransport();
Entry entry{convert::ToArray("key"), fidl::MakeOptional(std::move(buffer))};
EXPECT_THAT(entry, MatchesEntry({"key", "hello"}));
EXPECT_THAT(entry, MatchesEntry({Not("key2"), HasSubstr("ll")}));
}
TEST(LedgerMatcher, EntriesMatcher) {
fsl::SizedVmo size_vmo;
ASSERT_TRUE(fsl::VmoFromString("hello", &size_vmo));
fuchsia::mem::Buffer buffer = std::move(size_vmo).ToTransport();
Entry entry1{convert::ToArray("key1"), fidl::MakeOptional(std::move(buffer))};
ASSERT_TRUE(fsl::VmoFromString("hello2", &size_vmo));
buffer = std::move(size_vmo).ToTransport();
Entry entry2{convert::ToArray("key2"), fidl::MakeOptional(std::move(buffer))};
std::vector<Entry> entries;
entries.push_back(std::move(entry1));
entries.push_back(std::move(entry2));
EXPECT_THAT(entries, MatchEntries({{"key1", "hello"}, {"key2", "hello2"}}));
EXPECT_THAT(entries, MatchEntries({{"key1", HasSubstr("ll")},
{"key2", HasSubstr("ll")}}));
}
} // namespace
} // namespace ledger