1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2020 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#include "experimental/skrive/src/reader/StreamReader.h" 9cb93a386Sopenharmony_ci#include "tests/Test.h" 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ciusing namespace skrive::internal; 12cb93a386Sopenharmony_ci 13cb93a386Sopenharmony_ciDEF_TEST(SkRive_JsonReader, reporter) { 14cb93a386Sopenharmony_ci static constexpr char json[] = R"({ 15cb93a386Sopenharmony_ci "version": 24, 16cb93a386Sopenharmony_ci "artboards": [ 17cb93a386Sopenharmony_ci { 18cb93a386Sopenharmony_ci "name" : "artboard 1", 19cb93a386Sopenharmony_ci "translation" : [ 24, 42 ], 20cb93a386Sopenharmony_ci "width" : 500, 21cb93a386Sopenharmony_ci "height" : 250, 22cb93a386Sopenharmony_ci "origin" : [ 100, 100 ], 23cb93a386Sopenharmony_ci "clipContents": true, 24cb93a386Sopenharmony_ci "color" : [ 1, 1, 0, 1], 25cb93a386Sopenharmony_ci "type" : "artboard" 26cb93a386Sopenharmony_ci } 27cb93a386Sopenharmony_ci ] 28cb93a386Sopenharmony_ci })"; 29cb93a386Sopenharmony_ci 30cb93a386Sopenharmony_ci auto sr = StreamReader::Make(SkData::MakeWithoutCopy(json, strlen(json))); 31cb93a386Sopenharmony_ci 32cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, sr); 33cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, sr->readUInt32("version") == 24); 34cb93a386Sopenharmony_ci { 35cb93a386Sopenharmony_ci StreamReader::AutoBlock ab(sr); 36cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, ab.type() == StreamReader::BlockType::kArtboards); 37cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, sr->readLength16() == 1); 38cb93a386Sopenharmony_ci 39cb93a386Sopenharmony_ci { 40cb93a386Sopenharmony_ci StreamReader::AutoBlock ab(sr); 41cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, ab.type() == StreamReader::BlockType::kActorArtboard); 42cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, sr->readString("name").equals("artboard 1")); 43cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, sr->readV2("translation") == (SkV2{24,42})); 44cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, sr->readFloat("width" ) == 500); 45cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, sr->readFloat("height") == 250); 46cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, sr->readV2("origin") == (SkV2{100,100})); 47cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, sr->readBool("clipContents")); 48cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, sr->readColor("color") == (SkColor4f{1,1,0,1})); 49cb93a386Sopenharmony_ci 50cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, sr->readString("INVALID").equals("")); 51cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, sr->readFloat("INVALID" ) == 0); 52cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, !sr->readBool("INVALID")); 53cb93a386Sopenharmony_ci } 54cb93a386Sopenharmony_ci { 55cb93a386Sopenharmony_ci StreamReader::AutoBlock ab(sr); 56cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, ab.type() == StreamReader::BlockType::kEoB); 57cb93a386Sopenharmony_ci } 58cb93a386Sopenharmony_ci } 59cb93a386Sopenharmony_ci { 60cb93a386Sopenharmony_ci StreamReader::AutoBlock ab(sr); 61cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, ab.type() == StreamReader::BlockType::kEoB); 62cb93a386Sopenharmony_ci } 63cb93a386Sopenharmony_ci} 64