Flutter Engine
The Flutter Engine
shader_archive_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"
11
12namespace impeller {
13namespace testing {
14
15static 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
23const std::string CreateStringFromMapping(const fml::Mapping& mapping) {
24 return std::string{reinterpret_cast<const char*>(mapping.GetMapping()),
25 mapping.GetSize()};
26}
27
28TEST(ShaderArchiveTest, CanReadAndWriteBlobs) {
30 ASSERT_TRUE(writer.AddShader(ArchiveShaderType::kVertex, "Hello",
31 CreateMappingFromString("World")));
32 ASSERT_TRUE(writer.AddShader(ArchiveShaderType::kFragment, "Foo",
34 ASSERT_TRUE(writer.AddShader(ArchiveShaderType::kVertex, "Baz",
36 ASSERT_TRUE(writer.AddShader(ArchiveShaderType::kVertex, "Ping",
38 ASSERT_TRUE(writer.AddShader(ArchiveShaderType::kFragment, "Pang",
39 CreateMappingFromString("World")));
40
41 auto mapping = writer.CreateMapping();
42 ASSERT_NE(mapping, nullptr);
43
44 ShaderArchive library(mapping);
45 ASSERT_TRUE(library.IsValid());
46 ASSERT_EQ(library.GetShaderCount(), 5u);
47
48 // Wrong type.
49 ASSERT_EQ(library.GetMapping(ArchiveShaderType::kFragment, "Hello"), nullptr);
50
51 auto hello_vtx = library.GetMapping(ArchiveShaderType::kVertex, "Hello");
52 ASSERT_NE(hello_vtx, nullptr);
53 ASSERT_EQ(CreateStringFromMapping(*hello_vtx), "World");
54}
55
56} // namespace testing
57} // namespace impeller
virtual const uint8_t * GetMapping() const =0
virtual size_t GetSize() const =0
bool AddShader(ArchiveShaderType type, std::string name, std::shared_ptr< fml::Mapping > mapping)
std::shared_ptr< fml::Mapping > CreateMapping() const
size_t GetShaderCount() const
std::shared_ptr< fml::Mapping > GetMapping(ArchiveShaderType type, std::string name) const
const std::string CreateStringFromMapping(const fml::Mapping &mapping)
TEST(AiksCanvasTest, EmptyCullRect)
static std::shared_ptr< fml::Mapping > CreateMappingFromString(std::string p_string)