static void TestPDFDict(skiatest::Reporter* reporter) { SkAutoTUnref<SkPDFDict> dict(new SkPDFDict); ASSERT_EMIT_EQ(reporter, *dict, "<<>>"); dict->insertInt("n1", SkToSizeT(42)); ASSERT_EMIT_EQ(reporter, *dict, "<</n1 42>>"); dict.reset(new SkPDFDict); ASSERT_EMIT_EQ(reporter, *dict, "<<>>"); dict->insertInt("n1", 42); ASSERT_EMIT_EQ(reporter, *dict, "<</n1 42>>"); dict->insertScalar("n2", SK_ScalarHalf); SkString n3("n3"); SkAutoTUnref<SkPDFArray> innerArray(new SkPDFArray); innerArray->appendInt(-100); dict->insertObject(n3, innerArray.detach()); ASSERT_EMIT_EQ(reporter, *dict, "<</n1 42\n/n2 0.5\n/n3 [-100]>>"); dict.reset(new SkPDFDict); ASSERT_EMIT_EQ(reporter, *dict, "<<>>"); dict->insertInt("n1", 24); ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24>>"); dict->insertInt("n2", SkToSizeT(99)); ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24\n/n2 99>>"); dict->insertScalar("n3", SK_ScalarHalf); ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24\n/n2 99\n/n3 0.5>>"); dict->insertName("n4", "AName"); ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24\n/n2 99\n/n3 0.5\n/n4 /AName>>"); dict->insertName("n5", SkString("AnotherName")); ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24\n/n2 99\n/n3 0.5\n/n4 /AName\n" "/n5 /AnotherName>>"); dict->insertString("n6", "A String"); ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24\n/n2 99\n/n3 0.5\n/n4 /AName\n" "/n5 /AnotherName\n/n6 (A String)>>"); dict->insertString("n7", SkString("Another String")); ASSERT_EMIT_EQ(reporter, *dict, "<</n1 24\n/n2 99\n/n3 0.5\n/n4 /AName\n" "/n5 /AnotherName\n/n6 (A String)\n/n7 (Another String)>>"); dict.reset(new SkPDFDict("DType")); ASSERT_EMIT_EQ(reporter, *dict, "<</Type /DType>>"); SkAutoTUnref<SkPDFArray> referencedArray(new SkPDFArray); Catalog catalog; catalog.numbers.addObject(referencedArray.get()); REPORTER_ASSERT(reporter, catalog.numbers.getObjectNumber( referencedArray.get()) == 1); dict->insertObjRef("n1", referencedArray.detach()); SkString result = emit_to_string(*dict, &catalog); ASSERT_EQ(reporter, result, "<</Type /DType\n/n1 1 0 R>>"); }
std::string CreateEncodedProposalObject(const UniValue& objJSON) { UniValue innerArray(UniValue::VARR); innerArray.push_back(UniValue("proposal")); innerArray.push_back(objJSON); UniValue outerArray(UniValue::VARR); outerArray.push_back(innerArray); std::string strData = outerArray.write(); std::string strHex = HexStr(strData); return strHex; }
static void TestPDFDict(skiatest::Reporter* reporter) { std::unique_ptr<SkPDFDict> dict(new SkPDFDict); assert_emit_eq(reporter, *dict, "<<>>"); dict->insertInt("n1", SkToSizeT(42)); assert_emit_eq(reporter, *dict, "<</n1 42>>"); dict.reset(new SkPDFDict); assert_emit_eq(reporter, *dict, "<<>>"); dict->insertInt("n1", 42); assert_emit_eq(reporter, *dict, "<</n1 42>>"); dict->insertScalar("n2", SK_ScalarHalf); SkString n3("n3"); std::unique_ptr<SkPDFArray> innerArray(new SkPDFArray); innerArray->appendInt(-100); dict->insertObject(n3, std::move(innerArray)); assert_emit_eq(reporter, *dict, "<</n1 42\n/n2 .5\n/n3 [-100]>>"); dict.reset(new SkPDFDict); assert_emit_eq(reporter, *dict, "<<>>"); dict->insertInt("n1", 24); assert_emit_eq(reporter, *dict, "<</n1 24>>"); dict->insertInt("n2", SkToSizeT(99)); assert_emit_eq(reporter, *dict, "<</n1 24\n/n2 99>>"); dict->insertScalar("n3", SK_ScalarHalf); assert_emit_eq(reporter, *dict, "<</n1 24\n/n2 99\n/n3 .5>>"); dict->insertName("n4", "AName"); assert_emit_eq(reporter, *dict, "<</n1 24\n/n2 99\n/n3 .5\n/n4 /AName>>"); dict->insertName("n5", SkString("AnotherName")); assert_emit_eq(reporter, *dict, "<</n1 24\n/n2 99\n/n3 .5\n/n4 /AName\n" "/n5 /AnotherName>>"); dict->insertString("n6", "A String"); assert_emit_eq(reporter, *dict, "<</n1 24\n/n2 99\n/n3 .5\n/n4 /AName\n" "/n5 /AnotherName\n/n6 (A String)>>"); dict->insertString("n7", SkString("Another String")); assert_emit_eq(reporter, *dict, "<</n1 24\n/n2 99\n/n3 .5\n/n4 /AName\n" "/n5 /AnotherName\n/n6 (A String)\n/n7 (Another String)>>"); dict.reset(new SkPDFDict("DType")); assert_emit_eq(reporter, *dict, "<</Type /DType>>"); }
static void TestPDFArray(skiatest::Reporter* reporter) { SkAutoTUnref<SkPDFArray> array(new SkPDFArray); ASSERT_EMIT_EQ(reporter, *array, "[]"); array->appendInt(42); ASSERT_EMIT_EQ(reporter, *array, "[42]"); array->appendScalar(SK_ScalarHalf); ASSERT_EMIT_EQ(reporter, *array, "[42 0.5]"); array->appendInt(0); ASSERT_EMIT_EQ(reporter, *array, "[42 0.5 0]"); array->appendBool(true); ASSERT_EMIT_EQ(reporter, *array, "[42 0.5 0 true]"); array->appendName("ThisName"); ASSERT_EMIT_EQ(reporter, *array, "[42 0.5 0 true /ThisName]"); array->appendName(SkString("AnotherName")); ASSERT_EMIT_EQ(reporter, *array, "[42 0.5 0 true /ThisName /AnotherName]"); array->appendString("This String"); ASSERT_EMIT_EQ(reporter, *array, "[42 0.5 0 true /ThisName /AnotherName (This String)]"); array->appendString(SkString("Another String")); ASSERT_EMIT_EQ(reporter, *array, "[42 0.5 0 true /ThisName /AnotherName (This String) " "(Another String)]"); SkAutoTUnref<SkPDFArray> innerArray(new SkPDFArray); innerArray->appendInt(-1); array->appendObject(innerArray.detach()); ASSERT_EMIT_EQ(reporter, *array, "[42 0.5 0 true /ThisName /AnotherName (This String) " "(Another String) [-1]]"); SkAutoTUnref<SkPDFArray> referencedArray(new SkPDFArray); Catalog catalog; catalog.numbers.addObject(referencedArray.get()); REPORTER_ASSERT(reporter, catalog.numbers.getObjectNumber( referencedArray.get()) == 1); array->appendObjRef(referencedArray.detach()); SkString result = emit_to_string(*array, &catalog); ASSERT_EQ(reporter, result, "[42 0.5 0 true /ThisName /AnotherName (This String) " "(Another String) [-1] 1 0 R]"); }
static void TestPDFArray(skiatest::Reporter* reporter) { std::unique_ptr<SkPDFArray> array(new SkPDFArray); assert_emit_eq(reporter, *array, "[]"); array->appendInt(42); assert_emit_eq(reporter, *array, "[42]"); array->appendScalar(SK_ScalarHalf); assert_emit_eq(reporter, *array, "[42 .5]"); array->appendInt(0); assert_emit_eq(reporter, *array, "[42 .5 0]"); array->appendBool(true); assert_emit_eq(reporter, *array, "[42 .5 0 true]"); array->appendName("ThisName"); assert_emit_eq(reporter, *array, "[42 .5 0 true /ThisName]"); array->appendName(SkString("AnotherName")); assert_emit_eq(reporter, *array, "[42 .5 0 true /ThisName /AnotherName]"); array->appendString("This String"); assert_emit_eq(reporter, *array, "[42 .5 0 true /ThisName /AnotherName (This String)]"); array->appendString(SkString("Another String")); assert_emit_eq(reporter, *array, "[42 .5 0 true /ThisName /AnotherName (This String) " "(Another String)]"); std::unique_ptr<SkPDFArray> innerArray(new SkPDFArray); innerArray->appendInt(-1); array->appendObject(std::move(innerArray)); assert_emit_eq(reporter, *array, "[42 .5 0 true /ThisName /AnotherName (This String) " "(Another String) [-1]]"); }