forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapping_unittests.cc
63 lines (52 loc) · 1.99 KB
/
mapping_unittests.cc
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
// Copyright 2013 The Flutter 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 "flutter/fml/mapping.h"
#include "flutter/testing/testing.h"
namespace fml {
TEST(MallocMapping, EmptyContructor) {
MallocMapping mapping;
ASSERT_EQ(nullptr, mapping.GetMapping());
ASSERT_EQ(0u, mapping.GetSize());
}
TEST(MallocMapping, NotEmptyContructor) {
size_t length = 10;
MallocMapping mapping(reinterpret_cast<uint8_t*>(malloc(length)), length);
ASSERT_NE(nullptr, mapping.GetMapping());
ASSERT_EQ(length, mapping.GetSize());
}
TEST(MallocMapping, MoveConstructor) {
size_t length = 10;
MallocMapping mapping(reinterpret_cast<uint8_t*>(malloc(length)), length);
MallocMapping moved = std::move(mapping);
ASSERT_EQ(nullptr,
mapping.GetMapping()); // NOLINT(clang-analyzer-cplusplus.Move)
ASSERT_EQ(0u, mapping.GetSize());
ASSERT_NE(nullptr, moved.GetMapping());
ASSERT_EQ(length, moved.GetSize());
}
TEST(MallocMapping, Copy) {
size_t length = 10;
MallocMapping mapping(reinterpret_cast<uint8_t*>(malloc(length)), length);
memset(const_cast<uint8_t*>(mapping.GetMapping()), 0xac, mapping.GetSize());
MallocMapping copied =
MallocMapping::Copy(mapping.GetMapping(), mapping.GetSize());
ASSERT_NE(mapping.GetMapping(), copied.GetMapping());
ASSERT_EQ(mapping.GetSize(), copied.GetSize());
ASSERT_EQ(
0, memcmp(mapping.GetMapping(), copied.GetMapping(), mapping.GetSize()));
}
TEST(MallocMapping, Release) {
size_t length = 10;
MallocMapping mapping(reinterpret_cast<uint8_t*>(malloc(length)), length);
free(const_cast<uint8_t*>(mapping.Release()));
ASSERT_EQ(nullptr, mapping.GetMapping());
ASSERT_EQ(0u, mapping.GetSize());
}
TEST(MallocMapping, IsDontNeedSafe) {
size_t length = 10;
MallocMapping mapping(reinterpret_cast<uint8_t*>(malloc(length)), length);
ASSERT_NE(nullptr, mapping.GetMapping());
ASSERT_FALSE(mapping.IsDontNeedSafe());
}
} // namespace fml