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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
/*
* Copyright © Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 or 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mir/shell/persistent_surface_store.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
namespace ms = mir::scene;
namespace msh = mir::shell;
//namespace mtd = mir::test::doubles;
using Id = msh::PersistentSurfaceStore::Id;
TEST(PersistentSurfaceStoreId, deserialising_wildly_incorrect_buffer_raises_exception)
{
EXPECT_THROW(Id{"bob"}, std::invalid_argument);
}
TEST(PersistentSurfaceStoreId, deserialising_invalid_buffer_raises_exception)
{
// This is the right size, but isn't a UUID because it lacks the XX-XX-XX structure
EXPECT_THROW(Id{"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, std::invalid_argument);
}
TEST(PersistentSurfaceStoreId, serialization_roundtrips_with_deserialization)
{
using namespace testing;
Id first_id;
auto const buf = first_id.serialize_to_string();
Id const second_id{buf};
EXPECT_THAT(second_id, Eq(first_id));
}
TEST(PersistentSurfaceStoreId, ids_assigned_evaluate_equal)
{
using namespace testing;
Id const first_id;
auto const second_id = first_id;
EXPECT_THAT(second_id, Eq(first_id));
}
TEST(PersistentSurfaceStoreId, equal_ids_hash_equally)
{
using namespace testing;
auto const uuid_string = "0744caf3-c8d9-4483-a005-3375c1954287";
Id const first_id{uuid_string};
Id const second_id{uuid_string};
EXPECT_THAT(std::hash<Id>()(second_id), Eq(std::hash<Id>()(first_id)));
}
TEST(PersistentSurfaceStoreId, can_assign_ids)
{
using namespace testing;
Id first_id;
Id second_id;
// Technically, there's a roughly 1-in-2^128 chance of a false fail here.
EXPECT_THAT(second_id, Not(Eq(first_id)));
second_id = first_id;
EXPECT_THAT(second_id, Eq(first_id));
}
|