Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('XVIZLoader#encode-and-parse', t => {
for (const tcName in TEST_CASES) {
const TEST_JSON = TEST_CASES[tcName];
const glbFileBuffer = encodeBinaryXVIZ(TEST_JSON, {flattenArrays: true});
const json = parseBinaryXVIZ(glbFileBuffer);
t.ok(
!Array.isArray(json.buffers),
`${tcName} Encoded and parsed XVIZ - has no JSON buffers field`
);
t.ok(
!Array.isArray(json.bufferViews),
`${tcName} Encoded and parsed XVIZ - has no JSON bufferViews field`
);
t.ok(
!Array.isArray(json.accessors),
`${tcName} Encoded and parsed XVIZ - has no JSON accessors field`
);
// const reference = toLowPrecision(packJsonArrays(TEST_JSON));
// t.deepEqual(
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import test from 'tape-catch';
import {XVIZObject, XVIZObjectCollection} from '@xviz/parser';
/* set default collection */
XVIZObject.setDefaultCollection(new XVIZObjectCollection());
test('XVIZObjectCollection#observe, get, getAll', t => {
const collection = new XVIZObjectCollection();
const object0 = collection.get('A');
t.notOk(object0, 'should not return XVIZ object');
collection.observe('A', 1000);
const object1 = collection.get('A');
t.ok(object1 instanceof XVIZObject, 'gets XVIZ object');
t.is(object1.id, 'A', 'XVIZ object id is correct');
collection.observe('A', 1001);
const object11 = collection.get('A');
t.is(object1, object11, 'gets the same XVIZ object');
tape('StreamSynchronizer#correct lookup with empty entries (explicit no-data)', t => {
resetXVIZConfigAndSettings();
setXVIZConfig({TIME_WINDOW: 3});
const STREAMS_WITH_NO_DATA_ENTRIES = new XVIZStreamBuffer();
STREAMS_WITH_NO_DATA_ENTRIES.timeslices = [
{
// start both with no-data entry
timestamp: 90,
streams: {
stream1: null,
stream2: null
}
},
{
// stream1 has entry
timestamp: 100,
streams: {
stream1: {value: 1}
}
},
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import {StreamSynchronizer, XVIZStreamBuffer, setXVIZConfig} from '@xviz/parser';
import tape from 'tape-catch';
import {equals} from 'math.gl';
import {resetXVIZConfigAndSettings} from '../config/config-utils';
// xviz data uses snake_case
/* eslint-disable camelcase */
/* NOTE: keep in sync with tests in log-synchronizer.spec.js */
const TEST_BUFFER = new XVIZStreamBuffer();
TEST_BUFFER.timeslices = [
{
timestamp: 50,
streams: {
log1: {value: 1},
log2: {value: 10}
}
},
{
timestamp: 100,
streams: {
log1: {value: 1},
log2: {value: 20}
}
},
{
} from 'streetscape.gl';
import {Form} from '@streetscape.gl/monochrome';
import {
XVIZ_CONFIG,
APP_SETTINGS,
MAPBOX_TOKEN,
MAP_STYLE,
XVIZ_STYLE,
CAR,
STYLES
} from './constants';
import {default as XVIZLoaderFactory} from './log-from-factory';
setXVIZConfig(XVIZ_CONFIG);
const TIMEFORMAT_SCALE = getXVIZConfig().TIMESTAMP_FORMAT === 'seconds' ? 1000 : 1;
// Pass through path & parameters to loaders
function buildLoaderOptions() {
const url = new URL(window.location);
// I prefer to work with an object
const params = {};
for (const [k, v] of url.searchParams.entries()) {
if (Number.isNaN(Number.parseFloat(v))) {
params[k] = v;
} else {
params[k] = Number.parseFloat(v);
}
}
const {
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import {setXVIZConfig, getXVIZConfig} from '@xviz/parser';
const defaultXVIZConfig = Object.assign({}, getXVIZConfig());
export function resetXVIZConfigAndSettings() {
setXVIZConfig(defaultXVIZConfig);
}
tape('parseXVIZData timeslice', t => {
resetXVIZConfigAndSettings();
setXVIZConfig({currentMajorVersion: 2});
// NOTE: no explicit type for this message yet.
let result = parseXVIZData({...TestTimesliceMessageV2}, {v2Type: 'state_update'});
t.equals(result.type, XVIZ_MESSAGE_TYPE.TIMESLICE, 'Message type set for timeslice');
t.equal(result.updateType, 'COMPLETE', 'XVIZ update type is parsed');
t.equals(
result.timestamp,
TestTimesliceMessageV2.updates[0].poses['/vehicle_pose'].timestamp,
'Message timestamp set from vehicle_pose'
);
// Incremental update
result = parseXVIZData(
{...TestTimesliceMessageV2, update_type: 'INCREMENTAL'},
{v2Type: 'state_update'}
);
t.equals(result.type, XVIZ_MESSAGE_TYPE.TIMESLICE, 'Message type set for timeslice');
t.equal(result.updateType, 'INCREMENTAL', 'XVIZ update type is parsed');
tape('parseXVIZData timeslice without parsing metadata (v1)', t => {
// NOTE: this is the the teleassist case where they don't have metadata
// before they start sending log data
resetXVIZConfigAndSettings();
setXVIZConfig({PRIMARY_POSE_STREAM: '/vehicle_pose'});
setXVIZConfig({currentMajorVersion: 1});
// NOTE: no explicit type for this message yet.
const metaMessage = parseXVIZData({...TestTimesliceMessageV1});
t.equals(metaMessage.type, XVIZ_MESSAGE_TYPE.TIMESLICE, 'Message type set for timeslice');
t.equals(
metaMessage.timestamp,
TestTimesliceMessageV1.vehicle_pose.time,
'Message timestamp set from timeslice'
);
t.ok(
metaMessage.streams['/test/stream'].pointCloud,
'v1 pointCloud is parsed even if metadata was not seen'
);
t.is(
metaMessage.streams['/test/stream'].features[0].type,
'points3d',
'pointCloud exposed in features'
);
t.deepEquals(metaMessage.streams['/test/stream'].pointCloud.ids, [1234], 'v1 ids are populated');
{...TestTimesliceMessageV2, update_type: 'INCREMENTAL'},
{v2Type: 'state_update'}
);
t.equals(result.type, XVIZ_MESSAGE_TYPE.TIMESLICE, 'Message type set for timeslice');
t.equal(result.updateType, 'INCREMENTAL', 'XVIZ update type is parsed');
// Deprecated 'snapshot' update type
result = parseXVIZData(
{...TestTimesliceMessageV2, update_type: 'SNAPSHOT'},
{v2Type: 'state_update'}
);
t.equals(result.type, XVIZ_MESSAGE_TYPE.TIMESLICE, 'Message type set for timeslice');
t.equal(result.updateType, 'INCREMENTAL', 'XVIZ update type is parsed');
// Unknown update type
result = parseXVIZData({...TestTimesliceMessageV2, update_type: ''}, {v2Type: 'state_update'});
t.equals(
result.type,
XVIZ_MESSAGE_TYPE.INCOMPLETE,
'Should not parse timeslice of unsupported update type'
);
t.end();
});
tape('parseXVIZData preProcessPrimitive type change', t => {
let calledPreProcess = false;
resetXVIZConfigAndSettings();
setXVIZConfig({currentMajorVersion: 1});
setXVIZConfig({
PRIMARY_POSE_STREAM: '/vehicle_pose',
preProcessPrimitive: ({primitive, streamName, time}) => {
calledPreProcess = true;
primitive.type = 'circle2d';
}
});
// NOTE: no explicit type for this message yet.
const metaMessage = parseXVIZData({...TestTimesliceMessageV1});
t.ok(calledPreProcess, 'Called preProcessPrimitive callback');
t.equals(
metaMessage.streams['/test/stream'].pointCloud,
null,
'There are no pointClouds in parsed object'
);
t.end();
});