skia2/experimental/skrive/tests/JsonReader.cpp
Florin Malita 45cd20004c [skrive] Initial artboard plumbing
"Artboards" are top-level Rive containers (similar to AE compositions),
holding the scene graphics and related animations.

Artboard properties:

  - name
  - width/height (size)
  - translation (position)
  - origin (anchor point for transforms?)
  - (background) color
  - clip contents flag

Plumb artboard parsing + background rendering, and hook into viewer.

TBR=
Change-Id: Ib188245ce41a76197cf9e0937689adf8243826d6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/295244
Reviewed-by: Florin Malita <fmalita@google.com>
Commit-Queue: Florin Malita <fmalita@google.com>
2020-06-09 19:58:38 +00:00

62 lines
2.6 KiB
C++

/*
* Copyright 2020 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "experimental/skrive/src/reader/StreamReader.h"
#include "tests/Test.h"
using namespace skrive::internal;
DEF_TEST(SkRive_JsonReader, reporter) {
static constexpr char json[] = R"({
"version": 24,
"artboards": [
{
"name" : "artboard 1",
"translation" : [ 24, 42 ],
"width" : 500,
"height" : 250,
"origin" : [ 100, 100 ],
"clipContents": true,
"color" : [ 1, 1, 0, 1],
"type" : "artboard"
}
]
})";
auto sr = StreamReader::Make(json, strlen(json));
REPORTER_ASSERT(reporter, sr);
{
StreamReader::AutoBlock ab(sr);
REPORTER_ASSERT(reporter, ab.type() == StreamReader::BlockType::kArtboards);
{
StreamReader::AutoBlock ab(sr);
REPORTER_ASSERT(reporter, ab.type() == StreamReader::BlockType::kActorArtboard);
REPORTER_ASSERT(reporter, sr->readString("name").equals("artboard 1"));
REPORTER_ASSERT(reporter, sr->readV2("translation") == (SkV2{24,42}));
REPORTER_ASSERT(reporter, sr->readFloat("width" ) == 500);
REPORTER_ASSERT(reporter, sr->readFloat("height") == 250);
REPORTER_ASSERT(reporter, sr->readV2("origin") == (SkV2{100,100}));
REPORTER_ASSERT(reporter, sr->readBool("clipContents"));
REPORTER_ASSERT(reporter, sr->readColor("color") == (SkColor4f{1,1,0,1}));
REPORTER_ASSERT(reporter, sr->readString("INVALID").equals(""));
REPORTER_ASSERT(reporter, sr->readFloat("INVALID" ) == 0);
REPORTER_ASSERT(reporter, !sr->readBool("INVALID"));
}
{
StreamReader::AutoBlock ab(sr);
REPORTER_ASSERT(reporter, ab.type() == StreamReader::BlockType::kEoB);
}
}
{
StreamReader::AutoBlock ab(sr);
REPORTER_ASSERT(reporter, ab.type() == StreamReader::BlockType::kEoB);
}
}