GCC Code Coverage Report


ernie/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
28 / 28
100.0%
Branches:
22 / 36
61.1%
Functions:
5 / 5
100.0%

scene/view.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 /// @file view.cpp
3 /// @brief Schema views' checks.
4 #include "ernie/scene/view.h"
5
6 #include <stdexcept>
7 #include <string>
8
9 namespace ernie {
10 namespace {
11
12 1297 bool IsApi(const SchemaDef& schema) {
13 1297 return schema.kind == SchemaKind::SingleApply || schema.kind == SchemaKind::MultipleApply;
14 }
15
16 1298 PrimId Check(const Scene& scene, const Path& path, const SchemaDef& schema,
17 std::string_view instance) {
18 1298 const PrimId prim = scene.Require(path);
19
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 1258 times.
1297 if (IsApi(schema)) {
20 39 const std::string api = ApiName{&schema, instance}.ToString();
21
3/4
✓ Branch 1 taken 39 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 36 times.
39 if (!scene.HasApi(prim, api)) {
22
3/6
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 3 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
12 throw std::invalid_argument("'" + path.String() + "' has no " + api + " applied");
23 }
24 36 return prim;
25 39 }
26 1258 const SchemaDef* type = scene.Schema(prim);
27
2/2
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1257 times.
1258 if (!IsA(type, schema)) {
28
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
1 const std::string_view name = type != nullptr ? type->name : "a prim without a type";
29
4/8
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 time.
✗ Branch 11 not taken.
4 throw std::invalid_argument("'" + path.String() + "' is " + std::string(name) + ", not a " +
30
2/4
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
✗ Branch 6 not taken.
3 std::string(schema.name));
31 }
32 1257 return prim;
33 }
34
35 } // namespace
36
37 11 SchemaView::SchemaView(const Scene& scene, const Path& path, const SchemaDef& schema,
38 11 std::string_view instance)
39 22 : scene_(&scene), prim_(Check(scene, path, schema, instance)), schema_(&schema),
40 11 instance_(instance) {}
41
42 1287 SchemaView::SchemaView(Scene& scene, const Path& path, const SchemaDef& schema,
43 1287 std::string_view instance)
44 1287 : scene_(&scene), mutable_(&scene), prim_(Check(scene, path, schema, instance)),
45 1282 schema_(&schema), instance_(instance) {}
46
47 1101 Scene& SchemaView::Edit() const {
48
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 1100 times.
1101 if (mutable_ == nullptr) {
49
3/6
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 time.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
3 throw std::logic_error("'" + GetPath().String() + "' was viewed in a const scene");
50 }
51 1100 return *mutable_;
52 }
53
54 } // namespace ernie
55