yzt
2023-05-26 de4278af2fd46705a40bac58ec01122db6b7f3d7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import { JsonMetadataTable } from "../../Source/Cesium.js";
 
describe("Scene/JsonMetadataTable", function () {
  var properties = {
    priority: [2, 1, 0],
    labels: ["Point Cloud", "Mesh", "Raster"],
    uri: ["tree.las", "building.gltf", "map.tif"],
    sizeInfo: [
      {
        pointCount: 100,
      },
      {
        vertices: 3000,
        faces: 1000,
      },
      {
        width: 1024,
        height: 1024,
      },
    ],
    mixedValues: ["red", 3, false],
  };
  var count = 3;
 
  var table;
  beforeEach(function () {
    table = new JsonMetadataTable({
      count: count,
      properties: properties,
    });
  });
 
  it("constructor throws without count", function () {
    expect(function () {
      return new JsonMetadataTable({
        count: undefined,
        properties: properties,
      });
    }).toThrowDeveloperError();
  });
 
  it("constructor throws without properties", function () {
    expect(function () {
      return new JsonMetadataTable({
        count: count,
        properties: undefined,
      });
    }).toThrowDeveloperError();
  });
 
  it("constructor clones properties", function () {
    var oldValue = properties.sizeInfo[0];
    var sizeInfo = {
      lengthBytes: 1024,
    };
    table.setProperty(0, "sizeInfo", sizeInfo);
    expect(properties.sizeInfo[0]).toBe(oldValue);
    expect(table.getProperty(0, "sizeInfo")).toEqual(sizeInfo);
  });
 
  it("hasProperty returns true if the table has this property", function () {
    expect(table.hasProperty("priority")).toBe(true);
  });
 
  it("hasProperty returns false if the table does not have this property", function () {
    expect(table.hasProperty("price")).toBe(false);
  });
 
  it("getPropertyIds returns a list of property Ids", function () {
    expect(table.getPropertyIds().sort()).toEqual([
      "labels",
      "mixedValues",
      "priority",
      "sizeInfo",
      "uri",
    ]);
  });
 
  it("getProperty returns undefined for unknown property Id", function () {
    expect(table.getProperty(0, "color")).not.toBeDefined();
  });
 
  it("getProperty throws without index", function () {
    expect(function () {
      return table.getProperty(undefined, "priority");
    }).toThrowDeveloperError();
  });
 
  it("getProperty throws for out-of-bounds index", function () {
    expect(function () {
      return table.getProperty(5, "priority");
    }).toThrowDeveloperError();
  });
 
  it("getProperty throws without propertyId", function () {
    expect(function () {
      return table.getProperty(5, undefined);
    }).toThrowDeveloperError();
  });
 
  it("getProperty returns the property value", function () {
    expect(table.getProperty(0, "priority")).toBe(2);
    expect(table.getProperty(1, "priority")).toBe(1);
    expect(table.getProperty(2, "priority")).toBe(0);
  });
 
  it("getProperty returns copy of value", function () {
    var value1 = table.getProperty(1, "sizeInfo");
    var value2 = table.getProperty(1, "sizeInfo");
    expect(value1).toEqual(properties.sizeInfo[1]);
    expect(value1).toEqual(value2);
    expect(value2).not.toBe(value1);
  });
 
  it("getProperty works with heterogeneous values", function () {
    expect(table.getProperty(0, "mixedValues")).toBe("red");
    expect(table.getProperty(1, "mixedValues")).toBe(3);
    expect(table.getProperty(2, "mixedValues")).toBe(false);
  });
 
  it("setProperty throws without index", function () {
    expect(function () {
      return table.setProperty(undefined, undefined);
    }).toThrowDeveloperError();
  });
 
  it("setProperty throws for out-of-bounds index", function () {
    expect(function () {
      return table.setProperty(5, "priority", 3);
    }).toThrowDeveloperError();
  });
 
  it("setProperty throws without propertyId", function () {
    expect(function () {
      return table.setProperty(5, undefined);
    }).toThrowDeveloperError();
  });
 
  it("setProperty returns false if property doesn't exist", function () {
    expect(table.setProperty(0, "color", [255, 255, 255, 1.0])).toBe(false);
  });
 
  it("setProperty sets property value", function () {
    var sizeInfo = {
      lengthBytes: 1024,
    };
    expect(table.setProperty(0, "sizeInfo", sizeInfo)).toBe(true);
    expect(table.getProperty(0, "sizeInfo")).toEqual(sizeInfo);
  });
 
  it("setProperty copies value", function () {
    var sizeInfo = {
      lengthBytes: 1024,
    };
    table.setProperty(1, "sizeInfo", sizeInfo);
    sizeInfo.offset = 8;
    expect(table.getProperty(1, "sizeInfo")).not.toEqual(sizeInfo);
  });
});