Flutter Impeller
blobcat_unittests.cc
Go to the documentation of this file.
1
// Copyright 2013 The Flutter Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#include <string>
6
7
#include "flutter/fml/mapping.h"
8
#include "flutter/testing/testing.h"
9
#include "
impeller/blobcat/blob_library.h
"
10
#include "
impeller/blobcat/blob_writer.h
"
11
12
namespace
impeller
{
13
namespace
testing {
14
15
static
std::shared_ptr<fml::Mapping>
CreateMappingFromString
(
16
std::string p_string) {
17
auto
string
= std::make_shared<std::string>(std::move(p_string));
18
return
std::make_shared<fml::NonOwnedMapping>(
19
reinterpret_cast<
const
uint8_t*
>
(string->data()), string->size(),
20
[
string
](
auto
,
auto
) {});
21
}
22
23
const
std::string
CreateStringFromMapping
(
const
fml::Mapping& mapping) {
24
return
std::string{
reinterpret_cast<
const
char
*
>
(mapping.GetMapping()),
25
mapping.GetSize()};
26
}
27
28
TEST
(BlobTest, CanReadAndWriteBlobs) {
29
BlobWriter
writer;
30
ASSERT_TRUE(writer.
AddBlob
(
BlobShaderType::kVertex
,
"Hello"
,
31
CreateMappingFromString
(
"World"
)));
32
ASSERT_TRUE(writer.
AddBlob
(
BlobShaderType::kFragment
,
"Foo"
,
33
CreateMappingFromString
(
"Bar"
)));
34
ASSERT_TRUE(writer.
AddBlob
(
BlobShaderType::kVertex
,
"Baz"
,
35
CreateMappingFromString
(
"Bang"
)));
36
ASSERT_TRUE(writer.
AddBlob
(
BlobShaderType::kVertex
,
"Ping"
,
37
CreateMappingFromString
(
"Pong"
)));
38
ASSERT_TRUE(writer.
AddBlob
(
BlobShaderType::kFragment
,
"Pang"
,
39
CreateMappingFromString
(
"World"
)));
40
41
auto
mapping = writer.
CreateMapping
();
42
ASSERT_NE(mapping,
nullptr
);
43
44
BlobLibrary
library(mapping);
45
ASSERT_TRUE(library.
IsValid
());
46
ASSERT_EQ(library.
GetShaderCount
(), 5u);
47
48
// Wrong type.
49
ASSERT_EQ(library.
GetMapping
(
BlobShaderType::kFragment
,
"Hello"
),
nullptr
);
50
51
auto
hello_vtx = library.
GetMapping
(
BlobShaderType::kVertex
,
"Hello"
);
52
ASSERT_NE(hello_vtx,
nullptr
);
53
ASSERT_EQ(
CreateStringFromMapping
(*hello_vtx),
"World"
);
54
}
55
56
}
// namespace testing
57
}
// namespace impeller
impeller::BlobWriter::CreateMapping
std::shared_ptr< fml::Mapping > CreateMapping() const
Definition:
blob_writer.cc:98
impeller::BlobLibrary
Definition:
blob_library.h:18
impeller::testing::CreateMappingFromString
static std::shared_ptr< fml::Mapping > CreateMappingFromString(std::string p_string)
Definition:
blobcat_unittests.cc:15
blob_library.h
impeller::testing::TEST
TEST(AiksCanvasTest, EmptyCullRect)
Definition:
canvas_unittests.cc:17
impeller::BlobWriter
Definition:
blob_writer.h:17
impeller::BlobLibrary::GetMapping
std::shared_ptr< fml::Mapping > GetMapping(BlobShaderType type, std::string name) const
Definition:
blob_library.cc:74
blob_writer.h
impeller::BlobWriter::AddBlob
bool AddBlob(BlobShaderType type, std::string name, std::shared_ptr< fml::Mapping > mapping)
Definition:
blob_writer.cc:74
impeller::BlobShaderType::kVertex
@ kVertex
impeller::BlobLibrary::GetShaderCount
size_t GetShaderCount() const
Definition:
blob_library.cc:70
impeller::testing::CreateStringFromMapping
const std::string CreateStringFromMapping(const fml::Mapping &mapping)
Definition:
blobcat_unittests.cc:23
impeller::BlobShaderType::kFragment
@ kFragment
impeller::BlobLibrary::IsValid
bool IsValid() const
Definition:
blob_library.cc:66
impeller
Definition:
aiks_context.cc:10
impeller
blobcat
blobcat_unittests.cc
Generated by
1.8.17