skottie_unittest.cc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (c) 2018 The Chromium 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. #include "testing/gtest/include/gtest/gtest.h"
  5. #include "third_party/skia/include/core/SkPixmap.h"
  6. #include "third_party/skia/include/core/SkStream.h"
  7. #include "third_party/skia/include/core/SkSurface.h"
  8. #include "third_party/skia/modules/skottie/include/Skottie.h"
  9. TEST(Skottie, Basic) {
  10. // Just a solid green layer.
  11. static constexpr char anim_data[] =
  12. "{"
  13. " \"v\" : \"4.12.0\","
  14. " \"fr\": 30,"
  15. " \"w\" : 400,"
  16. " \"h\" : 200,"
  17. " \"ip\": 0,"
  18. " \"op\": 150,"
  19. " \"assets\": [],"
  20. " \"layers\": ["
  21. " {"
  22. " \"ty\": 1,"
  23. " \"sw\": 400,"
  24. " \"sh\": 200,"
  25. " \"sc\": \"#00ff00\","
  26. " \"ip\": 0,"
  27. " \"op\": 150"
  28. " }"
  29. " ]"
  30. "}";
  31. SkMemoryStream stream(anim_data, strlen(anim_data));
  32. auto anim = skottie::Animation::Make(&stream);
  33. ASSERT_TRUE(anim);
  34. EXPECT_EQ(strcmp(anim->version().c_str(), "4.12.0"), 0);
  35. EXPECT_EQ(anim->size().width(), 400.0f);
  36. EXPECT_EQ(anim->size().height(), 200.0f);
  37. EXPECT_EQ(anim->duration(), 5.0f);
  38. auto surface = SkSurface::MakeRasterN32Premul(400, 200);
  39. anim->seek(0);
  40. anim->render(surface->getCanvas());
  41. SkPixmap pixmap;
  42. ASSERT_TRUE(surface->peekPixels(&pixmap));
  43. for (int i = 0; i < pixmap.width(); ++i) {
  44. for (int j = 0; j < pixmap.height(); ++j) {
  45. EXPECT_EQ(pixmap.getColor(i, j), 0xff00ff00);
  46. }
  47. }
  48. }