Best JavaScript code snippet using wpt
validate_gpkg.py
Source:validate_gpkg.py
...60 self.errors = []61 def _log(self, msg):62 if self.verbose:63 print(msg)64 def _assert(self, cond, req, msg):65 # self._log('Verified requirement %s' % req)66 if not cond:67 self.errors += [(req, msg)]68 if self.abort_at_first_error:69 if req:70 raise GPKGCheckException('Req %d: %s' % (req, msg))71 else:72 raise GPKGCheckException(msg)73 return cond74 def _check_structure(self, columns, expected_columns, req, table_name):75 self._assert(len(columns) == len(expected_columns), req,76 'Table %s has %d columns, whereas %d are expected' %77 (table_name, len(columns), len(expected_columns)))78 for (_, expected_name, expected_type, expected_notnull,79 expected_default, expected_pk) in expected_columns:80 found = False81 for (_, name, type, notnull, default, pk) in columns:82 if name != expected_name:83 continue84 if expected_type == 'INTEGER' and expected_pk:85 expected_notnull = 186 if type == 'INTEGER' and pk:87 notnull = 188 if not self.extended_pragma_info and expected_pk > 1:89 expected_pk = 190 self._assert(type == expected_type, req,91 'Wrong type for %s of %s. Expected %s, got %s' %92 (name, table_name, expected_type, type))93 self._assert(notnull == expected_notnull, req,94 ('Wrong notnull for %s of %s. ' +95 'Expected %s, got %s') %96 (name, table_name, expected_notnull, notnull))97 self._assert(default == expected_default, req,98 ('Wrong default for %s of %s. ' +99 'Expected %s, got %s') %100 (name, table_name, expected_default, default))101 self._assert(pk == expected_pk, req,102 'Wrong pk for %s of %s. Expected %s, got %s' %103 (name, table_name, expected_pk, pk))104 found = True105 break106 self._assert(found, req, 'Column %s of %s not found!' %107 (expected_name, table_name))108 def _check_gpkg_spatial_ref_sys(self, c):109 self._log('Checking gpkg_spatial_ref_sys')110 c.execute("SELECT 1 FROM sqlite_master WHERE "111 "name = 'gpkg_spatial_ref_sys'")112 if not self._assert(c.fetchone() is not None, 10,113 "gpkg_spatial_ref_sys table missing"):114 return115 c.execute("PRAGMA table_info(gpkg_spatial_ref_sys)")116 columns = c.fetchall()117 has_definition_12_063 = False118 for (_, name, _, _, _, _) in columns:119 if name == 'definition_12_063':120 has_definition_12_063 = True121 if has_definition_12_063:122 expected_columns = [123 (0, 'srs_name', 'TEXT', 1, None, 0),124 (1, 'srs_id', 'INTEGER', 1, None, 1),125 (2, 'organization', 'TEXT', 1, None, 0),126 (3, 'organization_coordsys_id', 'INTEGER', 1, None, 0),127 (4, 'definition', 'TEXT', 1, None, 0),128 (5, 'description', 'TEXT', 0, None, 0),129 (6, 'definition_12_063', 'TEXT', 1, None, 0)130 ]131 else:132 expected_columns = [133 (0, 'srs_name', 'TEXT', 1, None, 0),134 (1, 'srs_id', 'INTEGER', 1, None, 1),135 (2, 'organization', 'TEXT', 1, None, 0),136 (3, 'organization_coordsys_id', 'INTEGER', 1, None, 0),137 (4, 'definition', 'TEXT', 1, None, 0),138 (5, 'description', 'TEXT', 0, None, 0)139 ]140 self._check_structure(columns, expected_columns, 10,141 'gpkg_spatial_ref_sys')142 if has_definition_12_063:143 c.execute("SELECT srs_id, organization, organization_coordsys_id, "144 "definition, definition_12_063 "145 "FROM gpkg_spatial_ref_sys "146 "WHERE srs_id IN (-1, 0, 4326) ORDER BY srs_id")147 else:148 c.execute("SELECT srs_id, organization, organization_coordsys_id, "149 "definition FROM gpkg_spatial_ref_sys "150 "WHERE srs_id IN (-1, 0, 4326) ORDER BY srs_id")151 ret = c.fetchall()152 self._assert(ret[0][1] == 'NONE', 11,153 'wrong value for organization for srs_id = -1: %s' %154 ret[0][1])155 self._assert(ret[0][2] == -1, 11,156 'wrong value for organization_coordsys_id for '157 'srs_id = -1: %s' % ret[0][2])158 self._assert(ret[0][3] == 'undefined', 11,159 'wrong value for definition for srs_id = -1: %s' %160 ret[0][3])161 if has_definition_12_063:162 self._assert(ret[0][4] == 'undefined', 116,163 'wrong value for definition_12_063 for ' +164 'srs_id = -1: %s' % ret[0][4])165 self._assert(ret[1][1] == 'NONE', 11,166 'wrong value for organization for srs_id = 0: %s' %167 ret[1][1])168 self._assert(ret[1][2] == 0, 11,169 'wrong value for organization_coordsys_id for '170 'srs_id = 0: %s' % ret[1][2])171 self._assert(ret[1][3] == 'undefined', 11,172 'wrong value for definition for srs_id = 0: %s' %173 ret[1][3])174 if has_definition_12_063:175 self._assert(ret[1][4] == 'undefined', 116,176 'wrong value for definition_12_063 for ' +177 'srs_id = 0: %s' % ret[1][4])178 self._assert(ret[2][1].lower() == 'epsg', 11,179 'wrong value for organization for srs_id = 4326: %s' %180 ret[2][1])181 self._assert(ret[2][2] == 4326, 11,182 'wrong value for organization_coordsys_id for '183 'srs_id = 4326: %s' % ret[2][2])184 self._assert(ret[2][3] != 'undefined', 11,185 'wrong value for definition for srs_id = 4326: %s' %186 ret[2][3])187 if has_definition_12_063:188 self._assert(ret[2][4] != 'undefined', 116,189 'wrong value for definition_12_063 for ' +190 'srs_id = 4326: %s' % ret[2][4])191 if has_definition_12_063:192 c.execute("SELECT srs_id FROM gpkg_spatial_ref_sys "193 "WHERE srs_id NOT IN (0, -1) AND "194 "definition = 'undefined' AND "195 "definition_12_063 = 'undefined'")196 rows = c.fetchall()197 for (srs_id, ) in rows:198 self._assert(False, 117,199 'srs_id = %d has both definition and ' % srs_id +200 'definition_12_063 undefined')201 def _check_gpkg_contents(self, c):202 self._log('Checking gpkg_contents')203 c.execute("SELECT 1 FROM sqlite_master WHERE name = 'gpkg_contents'")204 self._assert(c.fetchone() is not None, 13,205 "gpkg_contents table missing")206 c.execute("PRAGMA table_info(gpkg_contents)")207 columns = c.fetchall()208 expected_columns = [209 (0, 'table_name', 'TEXT', 1, None, 1),210 (1, 'data_type', 'TEXT', 1, None, 0),211 (2, 'identifier', 'TEXT', 0, None, 0),212 (3, 'description', 'TEXT', 0, "''", 0),213 (4, 'last_change', 'DATETIME', 1,214 "strftime('%Y-%m-%dT%H:%M:%fZ','now')", 0),215 (5, 'min_x', 'DOUBLE', 0, None, 0),216 (6, 'min_y', 'DOUBLE', 0, None, 0),217 (7, 'max_x', 'DOUBLE', 0, None, 0),218 (8, 'max_y', 'DOUBLE', 0, None, 0),219 (9, 'srs_id', 'INTEGER', 0, None, 0)220 ]221 self._check_structure(columns, expected_columns, 13, 'gpkg_contents')222 c.execute("SELECT 1 FROM gpkg_contents "223 "WHERE data_type IN ('features', 'tiles')")224 self._assert(c.fetchone() is not None, 17,225 'gpkg_contents should at least have one table with '226 'data_type = features and/or tiles')227 c.execute("SELECT table_name, data_type FROM gpkg_contents "228 "WHERE data_type NOT IN "229 "('features', 'tiles', 'attributes', '2d-gridded-coverage')")230 ret = c.fetchall()231 self._assert(len(ret) == 0, 17,232 'Unexpected data types in gpkg_contents: %s' % str(ret))233 c.execute('SELECT table_name, last_change, srs_id FROM gpkg_contents')234 rows = c.fetchall()235 for (table_name, last_change, srs_id) in rows:236 c.execute("SELECT 1 FROM sqlite_master WHERE "237 "lower(name) = lower(?) AND type IN ('table', 'view')", (table_name,))238 self._assert(c.fetchone() is not None, 14,239 ('table_name=%s in gpkg_contents is not a ' +240 'table or view') % table_name)241 try:242 datetime.datetime.strptime(243 last_change, '%Y-%m-%dT%H:%M:%S.%fZ')244 except:245 self._assert(False, 15,246 ('last_change = %s for table_name = %s ' +247 'is invalid datetime') %248 (last_change, table_name))249 if srs_id is not None:250 c.execute('SELECT 1 FROM gpkg_spatial_ref_sys '251 'WHERE srs_id = ?', (srs_id, ))252 self._assert(c.fetchone() is not None, 14,253 ("table_name=%s has srs_id=%d in gpkg_contents " +254 "which isn't found in gpkg_spatial_ref_sys") %255 (table_name, srs_id))256 def _check_vector_user_table(self, c, table_name):257 self._log('Checking vector user table ' + table_name)258 c.execute("SELECT column_name, z, m, geometry_type_name, srs_id "259 "FROM gpkg_geometry_columns WHERE table_name = ?",260 (table_name,))261 rows_gpkg_geometry_columns = c.fetchall()262 self._assert(len(rows_gpkg_geometry_columns) == 1, 22,263 ('table_name = %s is not registered in ' +264 'gpkg_geometry_columns') % table_name)265 geom_column_name = rows_gpkg_geometry_columns[0][0]266 z = rows_gpkg_geometry_columns[0][1]267 m = rows_gpkg_geometry_columns[0][2]268 geometry_type_name = rows_gpkg_geometry_columns[0][3]269 srs_id = rows_gpkg_geometry_columns[0][4]270 c.execute('PRAGMA table_info(%s)' % table_name)271 base_geom_types = ('GEOMETRY', 'POINT', 'LINESTRING', 'POLYGON',272 'MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON',273 'GEOMETRYCOLLECTION')274 cols = c.fetchall()275 found_geom = False276 count_pkid = 0277 for (_, name, type, notnull, default, pk) in cols:278 if name.lower() == geom_column_name.lower():279 found_geom = True280 self._assert(281 type in base_geom_types or282 type in GPKGChecker.EXT_GEOM_TYPES,283 25, ('invalid type (%s) for geometry ' +284 'column of table %s') % (type, table_name))285 self._assert(type == geometry_type_name, 31,286 ('table %s has geometry column of type %s in ' +287 'SQL and %s in geometry_type_name of ' +288 'gpkg_geometry_columns') %289 (table_name, type, geometry_type_name))290 elif pk == 1:291 count_pkid += 1292 self._assert(type == 'INTEGER', 29,293 ('table %s has a PRIMARY KEY of type %s ' +294 'instead of INTEGER') % (table_name, type))295 else:296 self._assert(_is_valid_data_type(type), 5,297 ('table %s has column %s of unexpected type %s'298 % (table_name, name, type)))299 self._assert(found_geom, 24,300 'table %s has no %s column' %301 (table_name, geom_column_name))302 self._assert(count_pkid == 1, 29,303 'table %s has no INTEGER PRIMARY KEY' % table_name)304 self._assert(z in (0, 1, 2), 27, ("z value of %s is %d. " +305 "Expected 0, 1 or 2") % (table_name, z))306 self._assert(m in (0, 1, 2), 27, ("m value of %s is %d. " +307 "Expected 0, 1 or 2") % (table_name, m))308 if geometry_type_name in GPKGChecker.EXT_GEOM_TYPES:309 c.execute("SELECT 1 FROM gpkg_extensions WHERE "310 "extension_name = 'gpkg_geom_%s' AND "311 "table_name = ? AND column_name = ? AND "312 "scope = 'read-write'" % geometry_type_name,313 (table_name, geom_column_name))314 self._assert(c.fetchone() is not None, 68,315 "gpkg_geom_%s extension should be declared for "316 "table %s" % (geometry_type_name, table_name))317 wkb_geometries = base_geom_types + GPKGChecker.EXT_GEOM_TYPES318 c.execute("SELECT %s FROM %s " %319 (_esc_id(geom_column_name), _esc_id(table_name)))320 found_geom_types = set()321 for (blob,) in c.fetchall():322 if blob is None:323 continue324 self._assert(len(blob) >= 8, 19, 'Invalid geometry')325 max_size_needed = min(len(blob), 8 + 4 * 2 * 8 + 5)326 blob_ar = struct.unpack('B' * max_size_needed,327 blob[0:max_size_needed])328 self._assert(blob_ar[0] == ord('G'), 19, 'Invalid geometry')329 self._assert(blob_ar[1] == ord('P'), 19, 'Invalid geometry')330 self._assert(blob_ar[2] == 0, 19, 'Invalid geometry')331 flags = blob_ar[3]332 big_endian = (flags & 1) == 0333 env_ind = (flags >> 1) & 7334 self._assert(((flags >> 5) & 1) == 0, 19,335 'Invalid geometry: ExtendedGeoPackageBinary not '336 'allowed')337 self._assert(env_ind <= 4, 19,338 'Invalid geometry: invalid envelope indicator code')339 if big_endian:340 geom_srs_id = struct.unpack('>I' * 1, blob[4:8])[0]341 else:342 geom_srs_id = struct.unpack('<I' * 1, blob[4:8])[0]343 self._assert(srs_id == geom_srs_id, 33,344 ('table %s has geometries with SRID %d, ' +345 'whereas only %d is expected') %346 (table_name, geom_srs_id, srs_id))347 if env_ind == 0:348 coord_dim = 0349 elif env_ind == 1:350 coord_dim = 2351 elif env_ind == 2 or env_ind == 3:352 coord_dim = 3353 else:354 coord_dim = 4355 # if env_ind == 2 or env_ind == 4:356 # self._assert(z > 0, 19,357 # 'z found in geometry, but not in gpkg_geometry_columns')358 # if env_ind == 3 or env_ind == 4:359 # self._assert(m > 0, 19,360 # 'm found in geometry, but not in gpkg_geometry_columns')361 header_len = 8 + coord_dim * 2 * 8362 self._assert(len(blob) >= header_len, 19, 'Invalid geometry')363 wkb_endianness = blob_ar[header_len]364 wkb_big_endian = (wkb_endianness == 0)365 if wkb_big_endian:366 wkb_geom_type = struct.unpack(367 '>I' * 1, blob[header_len+1:header_len+5])[0]368 else:369 wkb_geom_type = struct.unpack(370 '<I' * 1, blob[header_len+1:header_len+5])[0]371 self._assert(wkb_geom_type >= 0 and372 (wkb_geom_type % 1000) < len(wkb_geometries),373 19, 'Invalid WKB geometry type')374 wkb_dim = int(wkb_geom_type / 1000)375 if z == 1:376 self._assert(wkb_dim == 1 or wkb_dim == 3, 19,377 'geometry without Z found')378 if m == 1:379 self._assert(wkb_dim == 2 or wkb_dim == 3, 19,380 'geometry without M found')381 if wkb_dim == 1 or wkb_dim == 3: # Z or ZM382 self._assert(z > 0, 19,383 'z found in geometry, but not in '384 'gpkg_geometry_columns')385 if wkb_dim == 2 or wkb_dim == 3: # M or ZM386 self._assert(m > 0, 19,387 'm found in geometry, but not in '388 'gpkg_geometry_columns')389 found_geom_types.add(wkb_geometries[wkb_geom_type % 1000])390 if geometry_type_name in ('POINT', 'LINESTRING', 'POLYGON',391 'MULTIPOINT', 'MULTILINESTRING',392 'MULTIPOLYGON'):393 self._assert(len(found_geom_types) == 0 or394 found_geom_types == set([geometry_type_name]), 32,395 'in table %s, found geometry types %s' %396 (table_name, str(found_geom_types)))397 elif geometry_type_name == 'GEOMETRYCOLLECTION':398 self._assert(len(found_geom_types) == 0 or399 len(found_geom_types.difference(400 set(['GEOMETRYCOLLECTION', 'MULTIPOINT',401 'MULTILINESTRING', 'MULTIPOLYGON',402 'MULTICURVE', 'MULTISURFACE']))) == 0, 32,403 'in table %s, found geometry types %s' %404 (table_name, str(found_geom_types)))405 elif geometry_type_name in ('CURVEPOLYGON', 'SURFACE'):406 self._assert(len(found_geom_types) == 0 or407 len(found_geom_types.difference(408 set(['POLYGON', 'CURVEPOLYGON']))) == 0, 32,409 'in table %s, found geometry types %s' %410 (table_name, str(found_geom_types)))411 elif geometry_type_name == 'MULTICURVE':412 self._assert(len(found_geom_types) == 0 or413 len(found_geom_types.difference(414 set(['MULTILINESTRING', 'MULTICURVE']))) == 0, 32,415 'in table %s, found geometry types %s' %416 (table_name, str(found_geom_types)))417 elif geometry_type_name == 'MULTISURFACE':418 self._assert(len(found_geom_types) == 0 or419 len(found_geom_types.difference(420 set(['MULTIPOLYGON', 'MULTISURFACE']))) == 0, 32,421 'in table %s, found geometry types %s' %422 (table_name, str(found_geom_types)))423 elif geometry_type_name == 'CURVE':424 self._assert(len(found_geom_types) == 0 or425 len(found_geom_types.difference(426 set(['LINESTRING', 'CIRCULARSTRING',427 'COMPOUNDCURVE']))) == 0, 32,428 'in table %s, found geometry types %s' %429 (table_name, str(found_geom_types)))430 for geom_type in found_geom_types:431 if geom_type in GPKGChecker.EXT_GEOM_TYPES:432 c.execute("SELECT 1 FROM gpkg_extensions WHERE "433 "extension_name = 'gpkg_geom_%s' AND "434 "table_name = ? AND column_name = ? AND "435 "scope = 'read-write'" % geom_type,436 (table_name, geom_column_name))437 self._assert(c.fetchone() is not None, 68,438 "gpkg_geom_%s extension should be declared for "439 "table %s" % (geom_type, table_name))440 rtree_name = 'rtree_%s_%s' % (table_name, geom_column_name)441 c.execute("SELECT 1 FROM sqlite_master WHERE name = ?", (rtree_name,))442 has_rtree = c.fetchone() is not None443 if has_rtree:444 c.execute("SELECT 1 FROM gpkg_extensions WHERE "445 "extension_name = 'gpkg_rtree_index' AND "446 "table_name=? AND column_name=? AND "447 "scope='write-only'",448 (table_name, geom_column_name))449 self._assert(c.fetchone() is not None, 78,450 ("Table %s has a RTree, but not declared in " +451 "gpkg_extensions") % table_name)452 c.execute('PRAGMA table_info(%s)' % rtree_name)453 columns = c.fetchall()454 expected_columns = [455 (0, 'id', '', 0, None, 0),456 (1, 'minx', '', 0, None, 0),457 (2, 'maxx', '', 0, None, 0),458 (3, 'miny', '', 0, None, 0),459 (4, 'maxy', '', 0, None, 0)460 ]461 self._check_structure(columns, expected_columns, 77, rtree_name)462 c.execute("SELECT 1 FROM sqlite_master WHERE type = 'trigger' " +463 "AND name = '%s_insert'" % rtree_name)464 self._assert(c.fetchone() is not None, 75,465 "%s_insert trigger missing" % rtree_name)466 for i in range(4):467 c.execute("SELECT 1 FROM sqlite_master WHERE " +468 "type = 'trigger' " +469 "AND name = '%s_update%d'" % (rtree_name, i+1))470 self._assert(c.fetchone() is not None, 75,471 "%s_update%d trigger missing" % (rtree_name, i+1))472 c.execute("SELECT 1 FROM sqlite_master WHERE type = 'trigger' " +473 "AND name = '%s_delete'" % rtree_name)474 self._assert(c.fetchone() is not None, 75,475 "%s_delete trigger missing" % rtree_name)476 def _check_features(self, c):477 self._log('Checking features')478 c.execute("SELECT 1 FROM gpkg_contents WHERE data_type = 'features'")479 if c.fetchone() is None:480 self._log('... No features table')481 return482 self._log('Checking gpkg_geometry_columns')483 c.execute("SELECT 1 FROM sqlite_master WHERE "484 "name = 'gpkg_geometry_columns'")485 self._assert(c.fetchone() is not None, 21,486 "gpkg_geometry_columns table missing")487 c.execute("PRAGMA table_info(gpkg_geometry_columns)")488 columns = c.fetchall()489 expected_columns = [490 (0, 'table_name', 'TEXT', 1, None, 1),491 (1, 'column_name', 'TEXT', 1, None, 2),492 (2, 'geometry_type_name', 'TEXT', 1, None, 0),493 (3, 'srs_id', 'INTEGER', 1, None, 0),494 (4, 'z', 'TINYINT', 1, None, 0),495 (5, 'm', 'TINYINT', 1, None, 0)496 ]497 self._check_structure(columns, expected_columns, 21,498 'gpkg_geometry_columns')499 c.execute("SELECT table_name FROM gpkg_contents WHERE "500 "data_type = 'features'")501 rows = c.fetchall()502 for (table_name,) in rows:503 self._check_vector_user_table(c, table_name)504 c.execute("SELECT table_name, srs_id FROM gpkg_geometry_columns")505 rows = c.fetchall()506 for (table_name, srs_id) in rows:507 c.execute("SELECT 1 FROM gpkg_contents WHERE table_name = ? " +508 "AND data_type='features'", (table_name,))509 ret = c.fetchall()510 self._assert(len(ret) == 1, 23,511 ('table_name = %s is registered in ' +512 'gpkg_geometry_columns, but not in gpkg_contents') %513 table_name)514 c.execute('SELECT 1 FROM gpkg_spatial_ref_sys WHERE ' +515 'srs_id = ?', (srs_id, ))516 self._assert(c.fetchone() is not None, 14,517 ("table_name=%s has srs_id=%d in " +518 "gpkg_geometry_columns which isn't found in " +519 "gpkg_spatial_ref_sys") % (table_name, srs_id))520 def _check_attributes(self, c):521 self._log('Checking attributes')522 c.execute("SELECT table_name FROM gpkg_contents WHERE "523 "data_type = 'attributes'")524 rows = c.fetchall()525 if len(rows) == 0:526 self._log('... No attributes table')527 for (table_name,) in rows:528 self._log('Checking attributes table ' + table_name)529 c.execute('PRAGMA table_info(%s)' % table_name)530 cols = c.fetchall()531 count_pkid = 0532 for (_, name, type, notnull, default, pk) in cols:533 if pk == 1:534 count_pkid += 1535 self._assert(type == 'INTEGER', 119,536 ('table %s has a PRIMARY KEY of type %s ' +537 'instead of INTEGER') % (table_name, type))538 else:539 self._assert(_is_valid_data_type(type), 5,540 'table %s has column %s of unexpected type %s'541 % (table_name, name, type))542 self._assert(count_pkid == 1, 119,543 'table %s has no INTEGER PRIMARY KEY' % table_name)544 def _check_tile_user_table(self, c, table_name, data_type):545 self._log('Checking tile pyramid user table ' + table_name)546 c.execute("PRAGMA table_info(%s)" % table_name)547 columns = c.fetchall()548 expected_columns = [549 (0, 'id', 'INTEGER', 0, None, 1),550 (1, 'zoom_level', 'INTEGER', 1, None, 0),551 (2, 'tile_column', 'INTEGER', 1, None, 0),552 (3, 'tile_row', 'INTEGER', 1, None, 0),553 (4, 'tile_data', 'BLOB', 1, None, 0)554 ]555 self._check_structure(columns, expected_columns, 54,556 'gpkg_tile_matrix_set')557 c.execute("SELECT DISTINCT zoom_level FROM %s" % _esc_id(table_name))558 rows = c.fetchall()559 for (zoom_level, ) in rows:560 c.execute("SELECT 1 FROM gpkg_tile_matrix WHERE table_name = ? "561 "AND zoom_level = ?", (table_name, zoom_level))562 self._assert(c.fetchone() is not None, 44,563 ("Table %s has data for zoom_level = %d, but no " +564 "corresponding row in gpkg_tile_matrix") %565 (table_name, zoom_level))566 zoom_other_levels = False567 c.execute("SELECT 1 FROM sqlite_master WHERE name = 'gpkg_extensions'")568 if c.fetchone() is not None:569 c.execute("SELECT column_name FROM gpkg_extensions WHERE "570 "table_name = ? "571 "AND extension_name = 'gpkg_zoom_other'", (table_name,))572 row = c.fetchone()573 if row is not None:574 (column_name, ) = row575 self._assert(column_name == 'tile_data', 88,576 'Wrong column_name in gpkg_extensions for '577 'gpkg_zoom_other')578 zoom_other_levels = True579 c.execute("SELECT zoom_level, pixel_x_size, pixel_y_size "580 "FROM gpkg_tile_matrix "581 "WHERE table_name = ? ORDER BY zoom_level", (table_name,))582 rows = c.fetchall()583 prev_zoom_level = None584 prev_pixel_x_size = None585 prev_pixel_y_size = None586 for (zoom_level, pixel_x_size, pixel_y_size) in rows:587 if prev_pixel_x_size is not None:588 self._assert(589 pixel_x_size < prev_pixel_x_size and590 pixel_y_size < prev_pixel_y_size,591 53,592 ('For table %s, pixel size are not consistent ' +593 'with zoom_level') % table_name)594 if prev_zoom_level is not None and \595 zoom_level == prev_zoom_level + 1 and not zoom_other_levels:596 self._assert(597 abs((pixel_x_size-prev_pixel_x_size/2) /598 prev_pixel_x_size) < 1e-5, 35,599 "Expected pixel_x_size=%f for zoom_level=%d. Got %f" %600 (prev_pixel_x_size/2, zoom_level, pixel_x_size))601 self._assert(602 abs((pixel_y_size-prev_pixel_y_size/2) /603 prev_pixel_y_size) < 1e-5, 35,604 "Expected pixel_y_size=%f for zoom_level=%d. Got %f" %605 (prev_pixel_y_size/2, zoom_level, pixel_y_size))606 prev_pixel_x_size = pixel_x_size607 prev_pixel_y_size = pixel_y_size608 prev_zoom_level = zoom_level609 c.execute("SELECT max_x - min_x, "610 " MIN(matrix_width * tile_width * pixel_x_size), "611 " MAX(matrix_width * tile_width * pixel_x_size), "612 " max_y - min_y, "613 " MIN(matrix_height * tile_height * pixel_y_size), "614 " MAX(matrix_height * tile_height * pixel_y_size) "615 "FROM gpkg_tile_matrix tm JOIN gpkg_tile_matrix_set tms "616 "ON tm.table_name = tms.table_name WHERE tm.table_name = ?",617 (table_name,))618 rows = c.fetchall()619 if len(rows) != 0:620 (dx, min_dx, max_dx, dy, min_dy, max_dy) = rows[0]621 self._assert(abs((min_dx - dx) / dx) < 1e-3 and622 abs((max_dx - dx) / dx) < 1e-3 and623 abs((min_dy - dy) / dy) < 1e-3 and624 abs((max_dy - dy) / dy) < 1e-3, 45,625 ("Inconsistent values in gpkg_tile_matrix and " +626 "gpkg_tile_matrix_set for table %s") % table_name)627 c.execute("SELECT DISTINCT zoom_level FROM %s" % _esc_id(table_name))628 rows = c.fetchall()629 for (zoom_level,) in rows:630 c.execute(("SELECT MIN(tile_column), MAX(tile_column), " +631 "MIN(tile_row), MAX(tile_row) FROM %s " +632 "WHERE zoom_level = %d") %633 (_esc_id(table_name), zoom_level))634 min_col, max_col, min_row, max_row = c.fetchone()635 c.execute("SELECT matrix_width, matrix_height FROM "636 "gpkg_tile_matrix "637 "WHERE table_name = ? AND zoom_level = ?",638 (table_name, zoom_level))639 rows2 = c.fetchall()640 if len(rows2) == 0:641 self._assert(False, 55,642 "Invalid zoom_level in %s" % table_name)643 else:644 matrix_width, matrix_height = rows2[0]645 self._assert(min_col >= 0 and min_col < matrix_width, 56,646 "Invalid tile_col in %s" % table_name)647 self._assert(min_row >= 0 and min_row < matrix_height, 57,648 "Invalid tile_row in %s" % table_name)649 c.execute("SELECT tile_data FROM %s" % _esc_id(table_name))650 found_jpeg = False651 found_png = False652 found_webp = False653 found_tiff = False654 for (blob,) in c.fetchall():655 self._assert(blob is not None and len(blob) >= 12, 19,656 'Invalid blob')657 max_size_needed = 12658 blob_ar = struct.unpack('B' * max_size_needed,659 blob[0:max_size_needed])660 is_jpeg = blob_ar[0:3] == (0xff, 0xd8, 0xff)661 is_png = blob_ar[0:4] == (0x89, 0x50, 0x4E, 0x47)662 is_webp = blob_ar[0:4] == (ord('R'), ord('I'),663 ord('F'), ord('F')) and \664 blob_ar[8:12] == (ord('W'), ord('E'), ord('B'), ord('P'))665 is_tiff = blob_ar[0:4] == (0x49, 0x49, 0x2A, 0x00) or \666 blob_ar[0:4] == (0x4D, 0x4D, 0x00, 0x2A)667 self._assert(is_jpeg or is_png or is_webp or is_tiff, 36,668 'Unrecognized image mime type')669 if data_type == 'tiles':670 self._assert(is_jpeg or is_png or is_webp, 36,671 'Unrecognized image mime type')672 elif data_type == '2d-gridded-coverage':673 self._assert(is_png or is_tiff, 36,674 'Unrecognized image mime type')675 if is_jpeg:676 found_jpeg = True677 if is_png:678 found_png = True679 if is_webp:680 found_webp = True681 if is_tiff:682 found_tiff = True683 if found_webp:684 self._assert(not found_png and not found_jpeg and not found_tiff,685 92,686 "Table %s should contain only webp tiles" %687 table_name)688 c.execute("SELECT 1 FROM gpkg_extensions WHERE "689 "table_name = ? AND column_name = 'tile_data' AND "690 "extension_name = 'gpkg_webp' AND "691 "scope = 'read-write'", (table_name, ))692 self._assert(c.fetchone() is not None, 91,693 ("Table %s has webp content, but not registered "694 "in gpkg_extensions" % table_name))695 def _check_tiles(self, c):696 self._log('Checking tiles')697 c.execute("SELECT 1 FROM gpkg_contents WHERE data_type IN "698 "('tiles', '2d-gridded-coverage')")699 if c.fetchone() is None:700 self._log('... No tiles table')701 return702 self._log('Checking gpkg_tile_matrix_set ')703 c.execute("SELECT 1 FROM sqlite_master WHERE "704 "name = 'gpkg_tile_matrix_set'")705 self._assert(c.fetchone() is not None, 38,706 "gpkg_tile_matrix_set table missing")707 c.execute("PRAGMA table_info(gpkg_tile_matrix_set)")708 columns = c.fetchall()709 expected_columns = [710 (0, 'table_name', 'TEXT', 1, None, 1),711 (1, 'srs_id', 'INTEGER', 1, None, 0),712 (2, 'min_x', 'DOUBLE', 1, None, 0),713 (3, 'min_y', 'DOUBLE', 1, None, 0),714 (4, 'max_x', 'DOUBLE', 1, None, 0),715 (5, 'max_y', 'DOUBLE', 1, None, 0)]716 self._check_structure(columns, expected_columns, 38,717 'gpkg_tile_matrix_set')718 c.execute("SELECT table_name, srs_id FROM gpkg_tile_matrix_set")719 rows = c.fetchall()720 for (table_name, srs_id) in rows:721 c.execute("SELECT 1 FROM gpkg_contents WHERE table_name = ? " +722 "AND data_type IN ('tiles', '2d-gridded-coverage')",723 (table_name,))724 ret = c.fetchall()725 self._assert(len(ret) == 1, 39,726 ('table_name = %s is registered in ' +727 'gpkg_tile_matrix_set, but not in gpkg_contents') %728 table_name)729 c.execute('SELECT 1 FROM gpkg_spatial_ref_sys WHERE srs_id = ?',730 (srs_id, ))731 self._assert(c.fetchone() is not None, 41,732 ("table_name=%s has srs_id=%d in " +733 "gpkg_tile_matrix_set which isn't found in " +734 "gpkg_spatial_ref_sys") % (table_name, srs_id))735 self._log('Checking gpkg_tile_matrix')736 c.execute("SELECT 1 FROM sqlite_master WHERE "737 "name = 'gpkg_tile_matrix'")738 self._assert(c.fetchone() is not None, 42,739 "gpkg_tile_matrix table missing")740 c.execute("PRAGMA table_info(gpkg_tile_matrix)")741 columns = c.fetchall()742 expected_columns = [743 (0, 'table_name', 'TEXT', 1, None, 1),744 (1, 'zoom_level', 'INTEGER', 1, None, 2),745 (2, 'matrix_width', 'INTEGER', 1, None, 0),746 (3, 'matrix_height', 'INTEGER', 1, None, 0),747 (4, 'tile_width', 'INTEGER', 1, None, 0),748 (5, 'tile_height', 'INTEGER', 1, None, 0),749 (6, 'pixel_x_size', 'DOUBLE', 1, None, 0),750 (7, 'pixel_y_size', 'DOUBLE', 1, None, 0)751 ]752 self._check_structure(columns, expected_columns, 42,753 'gpkg_tile_matrix')754 c.execute("SELECT table_name, zoom_level, matrix_width, "755 "matrix_height, tile_width, tile_height, pixel_x_size, "756 "pixel_y_size FROM gpkg_tile_matrix")757 rows = c.fetchall()758 for (table_name, zoom_level, matrix_width, matrix_height, tile_width,759 tile_height, pixel_x_size, pixel_y_size) in rows:760 c.execute("SELECT 1 FROM gpkg_contents WHERE table_name = ? "761 "AND data_type IN ('tiles', '2d-gridded-coverage')",762 (table_name,))763 ret = c.fetchall()764 self._assert(len(ret) == 1, 43,765 ('table_name = %s is registered in ' +766 'gpkg_tile_matrix, but not in gpkg_contents') %767 table_name)768 self._assert(zoom_level >= 0, 46,769 "Invalid zoom_level = %d for table %s" %770 (zoom_level, table_name))771 self._assert(matrix_width > 0, 47,772 "Invalid matrix_width = %d for table %s" %773 (matrix_width, table_name))774 self._assert(matrix_height > 0, 48,775 "Invalid matrix_height = %d for table %s" %776 (matrix_height, table_name))777 self._assert(tile_width > 0, 49,778 "Invalid tile_width = %d for table %s" %779 (tile_width, table_name))780 self._assert(tile_height > 0, 50,781 "Invalid tile_height = %d for table %s" %782 (tile_height, table_name))783 self._assert(pixel_x_size > 0, 51,784 "Invalid pixel_x_size = %f for table %s" %785 (pixel_x_size, table_name))786 self._assert(pixel_y_size > 0, 52,787 "Invalid pixel_y_size = %f for table %s" %788 (pixel_y_size, table_name))789 c.execute("SELECT table_name, data_type FROM gpkg_contents WHERE "790 "data_type IN ('tiles', '2d-gridded-coverage')")791 rows = c.fetchall()792 for (table_name, data_type) in rows:793 self._check_tile_user_table(c, table_name, data_type)794 def _check_tiled_gridded_elevation_data(self, c):795 self._log('Checking tiled gridded elevation data')796 c.execute("SELECT table_name FROM gpkg_contents WHERE "797 "data_type = '2d-gridded-coverage'")798 tables = c.fetchall()799 if len(tables) == 0:800 self._log('... No tiled gridded coverage table')801 return802 tables = [tables[i][0] for i in range(len(tables))]803 c.execute("SELECT 1 FROM sqlite_master WHERE "804 "name = 'gpkg_2d_gridded_coverage_ancillary'")805 self._assert(c.fetchone() is not None, 120,806 'gpkg_2d_gridded_coverage_ancillary table is missing')807 c.execute("PRAGMA table_info(gpkg_2d_gridded_coverage_ancillary)")808 columns = c.fetchall()809 expected_columns = [810 (0, 'id', 'INTEGER', 0, None, 1),811 (1, 'tile_matrix_set_name', 'TEXT', 1, None, 0),812 (2, 'datatype', 'TEXT', 1, "'integer'", 0),813 (3, 'scale', 'REAL', 1, '1.0', 0),814 (4, 'offset', 'REAL', 1, '0.0', 0),815 (5, 'precision', 'REAL', 0, '1.0', 0),816 (6, 'data_null', 'REAL', 0, None, 0)817 ]818 self._check_structure(columns, expected_columns, 120,819 'gpkg_2d_gridded_coverage_ancillary')820 c.execute("SELECT 1 FROM sqlite_master WHERE "821 "name = 'gpkg_2d_gridded_tile_ancillary'")822 self._assert(c.fetchone() is not None, 121,823 'gpkg_2d_gridded_tile_ancillary table is missing')824 c.execute("PRAGMA table_info(gpkg_2d_gridded_tile_ancillary)")825 columns = c.fetchall()826 expected_columns = [827 (0, 'id', 'INTEGER', 0, None, 1),828 (1, 'tpudt_name', 'TEXT', 1, None, 0),829 (2, 'tpudt_id', 'INTEGER', 1, None, 0),830 (3, 'scale', 'REAL', 1, '1.0', 0),831 (4, 'offset', 'REAL', 1, '0.0', 0),832 (5, 'min', 'REAL', 0, 'NULL', 0),833 (6, 'max', 'REAL', 0, 'NULL', 0),834 (7, 'mean', 'REAL', 0, 'NULL', 0),835 (8, 'std_dev', 'REAL', 0, 'NULL', 0)836 ]837 self._check_structure(columns, expected_columns, 121,838 'gpkg_2d_gridded_tile_ancillary')839 c.execute("SELECT srs_id, organization, organization_coordsys_id, "840 "definition FROM gpkg_spatial_ref_sys "841 "WHERE srs_id = 4979")842 ret = c.fetchall()843 self._assert(len(ret) == 1, 122,844 "gpkg_spatial_ref_sys shall have a row for srs_id=4979")845 self._assert(ret[0][1].lower() == 'epsg', 122,846 'wrong value for organization for srs_id = 4979: %s' %847 ret[0][1])848 self._assert(ret[0][2] == 4979, 122,849 ('wrong value for organization_coordsys_id for ' +850 'srs_id = 4979: %s') % ret[0][2])851 c.execute("SELECT 1 FROM sqlite_master WHERE name = 'gpkg_extensions'")852 self._assert(c.fetchone() is not None, 125,853 'gpkg_extensions does not exist')854 c.execute("SELECT table_name, column_name, definition, scope FROM "855 "gpkg_extensions WHERE "856 "extension_name = 'gpkg_elevation_tiles'")857 rows = c.fetchall()858 self._assert(len(rows) == 2 + len(tables), 125,859 "Wrong number of entries in gpkg_elevation_tiles with"860 "gpkg_elevation_tiles extension name")861 found_gpkg_2d_gridded_coverage_ancillary = False862 found_gpkg_2d_gridded_tile_ancillary = False863 expected_def = \864 'http://www.geopackage.org/spec/' \865 '#extension_tiled_gridded_elevation_data'866 for (table_name, column_name, definition, scope) in rows:867 if table_name == 'gpkg_2d_gridded_coverage_ancillary':868 found_gpkg_2d_gridded_coverage_ancillary = True869 self._assert(column_name is None, 125,870 "Wrong entry for "871 "gpkg_2d_gridded_coverage_ancillary "872 "in gpkg_extensions")873 self._assert(definition == expected_def, 125,874 "Wrong entry for "875 "gpkg_2d_gridded_coverage_ancillary "876 "in gpkg_extensions")877 self._assert(scope == 'read-write', 125,878 "Wrong entry for "879 "gpkg_2d_gridded_coverage_ancillary "880 "in gpkg_extensions")881 elif table_name == 'gpkg_2d_gridded_tile_ancillary':882 found_gpkg_2d_gridded_tile_ancillary = True883 self._assert(column_name is None, 125,884 "Wrong entry for "885 "gpkg_2d_gridded_tile_ancillary "886 "in gpkg_extensions")887 self._assert(definition == expected_def, 125,888 "Wrong entry for "889 "gpkg_2d_gridded_tile_ancillary "890 "in gpkg_extensions")891 self._assert(scope == 'read-write', 125,892 "Wrong entry for "893 "gpkg_2d_gridded_tile_ancillary "894 "in gpkg_extensions")895 else:896 self._assert(table_name in tables, 125,897 "Unexpected table_name registered for " +898 "gpkg_elevation_tiles: %s" % table_name)899 self._assert(column_name == 'tile_data', 125,900 "Wrong entry for %s " % table_name +901 "in gpkg_extensions")902 self._assert(definition == expected_def, 125,903 "Wrong entry for %s " % table_name +904 "in gpkg_extensions")905 self._assert(scope == 'read-write', 125,906 "Wrong entry for %s " % table_name +907 "in gpkg_extensions")908 self._assert(found_gpkg_2d_gridded_coverage_ancillary, 125,909 "gpkg_2d_gridded_coverage_ancillary not registered "910 "for gpkg_elevation_tiles")911 self._assert(found_gpkg_2d_gridded_tile_ancillary, 125,912 "gpkg_2d_gridded_tile_ancillary not registered "913 "for gpkg_elevation_tiles")914 c.execute("SELECT tile_matrix_set_name, datatype FROM "915 "gpkg_2d_gridded_coverage_ancillary")916 rows = c.fetchall()917 self._assert(len(rows) == len(tables), 126,918 "Wrong number of entries in "919 "gpkg_2d_gridded_coverage_ancillary")920 for (tile_matrix_set_name, datatype) in rows:921 self._assert(tile_matrix_set_name in tables, 126,922 "Table %s has a row in " % tile_matrix_set_name +923 "gpkg_2d_gridded_coverage_ancillary, but not in "924 "gpkg_contents")925 c.execute('SELECT 1 FROM gpkg_tile_matrix_set WHERE '926 'table_name = ?', (tile_matrix_set_name,))927 self._assert(c.fetchone() is not None, 127,928 'missing entry in gpkg_tile_matrix_set ' +929 'for %s' % tile_matrix_set_name)930 self._assert(datatype in ('integer', 'float'), 128,931 'Unexpected datatype = %s' % datatype)932 for table in tables:933 c.execute("SELECT COUNT(*) FROM %s" % _esc_id(table))934 count_tpudt = c.fetchone()935 c.execute("SELECT COUNT(*) FROM gpkg_2d_gridded_tile_ancillary "936 "WHERE tpudt_name = ?", (table, ))937 count_tile_ancillary = c.fetchone()938 self._assert(count_tpudt == count_tile_ancillary, 129,939 ("Inconsistent number of rows in " +940 "gpkg_2d_gridded_tile_ancillary for %s") % table)941 c.execute("SELECT DISTINCT tpudt_name FROM "942 "gpkg_2d_gridded_tile_ancillary")943 rows = c.fetchall()944 for (tpudt_name, ) in rows:945 self._assert(tpudt_name in tables, 130,946 "tpudt_name = %s is invalid" % tpudt_name)947 c.execute("SELECT tile_matrix_set_name FROM "948 "gpkg_2d_gridded_coverage_ancillary WHERE "949 "datatype = 'float'")950 rows = c.fetchall()951 for (tile_matrix_set_name, ) in rows:952 c.execute("SELECT 1 FROM gpkg_2d_gridded_tile_ancillary WHERE "953 "tpudt_name = ? AND "954 "NOT (offset == 0.0 AND scale == 1.0)",955 (tile_matrix_set_name,))956 self._assert(len(c.fetchall()) == 0, 130,957 "Wrong scale and offset values " +958 "for %s " % tile_matrix_set_name +959 "in gpkg_2d_gridded_coverage_ancillary")960 for table in tables:961 c.execute("SELECT 1 FROM gpkg_2d_gridded_tile_ancillary WHERE " +962 "tpudt_name = ? AND tpudt_id NOT IN (SELECT id FROM " +963 "%s)" % table, (table,))964 self._assert(len(c.fetchall()) == 0, 131,965 "tpudt_id in gpkg_2d_gridded_coverage_ancillary " +966 "not referencing an id from %s" % table)967 c.execute("SELECT tile_matrix_set_name, datatype FROM "968 "gpkg_2d_gridded_coverage_ancillary")969 rows = c.fetchall()970 warn_gdal_not_available = False971 for (table_name, datatype) in rows:972 c.execute("SELECT id, tile_data FROM %s" % _esc_id(table_name))973 for (id, blob) in c.fetchall():974 self._assert(blob is not None and len(blob) >= 12, 19,975 'Invalid blob')976 max_size_needed = 12977 blob_ar = struct.unpack('B' * max_size_needed,978 blob[0:max_size_needed])979 is_png = blob_ar[0:4] == (0x89, 0x50, 0x4E, 0x47)980 is_tiff = blob_ar[0:4] == (0x49, 0x49, 0x2A, 0x00) or \981 blob_ar[0:4] == (0x4D, 0x4D, 0x00, 0x2A)982 if datatype == 'integer':983 self._assert(is_png, 132,984 'Tile for %s should be PNG' % table_name)985 if has_gdal:986 tmp_file = '/vsimem/temp_validate_gpkg.tif'987 try:988 blob = bytes(blob)989 except:990 blob = str(blob)991 gdal.FileFromMemBuffer(tmp_file, blob)992 ds = gdal.Open(tmp_file)993 try:994 self._assert(ds is not None, 132,995 'Invalid tile %d in %s' %996 (id, table_name))997 self._assert(ds.RasterCount == 1, 132,998 'Invalid tile %d in %s' %999 (id, table_name))1000 self._assert(ds.GetRasterBand(1).DataType ==1001 gdal.GDT_UInt16, 132,1002 'Invalid tile %d in %s' %1003 (id, table_name))1004 finally:1005 gdal.Unlink(tmp_file)1006 else:1007 if not warn_gdal_not_available:1008 warn_gdal_not_available = True1009 self._log('GDAL not available. Req 132 not tested')1010 elif datatype == 'float':1011 self._assert(is_tiff, 133,1012 'Tile for %s should be TIFF' % table_name)1013 if has_gdal:1014 tmp_file = '/vsimem/temp_validate_gpkg.tif'1015 try:1016 blob = bytes(blob)1017 except:1018 blob = str(blob)1019 gdal.FileFromMemBuffer(tmp_file, blob)1020 ds = gdal.Open(tmp_file)1021 try:1022 self._assert(ds is not None, 134,1023 'Invalid tile %d in %s' %1024 (id, table_name))1025 self._assert(ds.RasterCount == 1, 135,1026 'Invalid tile %d in %s' %1027 (id, table_name))1028 self._assert(ds.GetRasterBand(1).DataType ==1029 gdal.GDT_Float32, 136,1030 'Invalid tile %d in %s' %1031 (id, table_name))1032 compression = ds.GetMetadataItem('COMPRESSION',1033 'IMAGE_STRUCTURE')1034 self._assert(compression is None or1035 compression == 'LZW', 137,1036 'Invalid tile %d in %s' %1037 (id, table_name))1038 ovr_count = ds.GetRasterBand(1).GetOverviewCount()1039 self._assert(len(ds.GetSubDatasets()) == 0 and1040 ovr_count == 0, 138,1041 'Invalid tile %d in %s' %1042 (id, table_name))1043 (blockxsize, _) = \1044 ds.GetRasterBand(1).GetBlockSize()1045 self._assert(blockxsize == ds.RasterXSize, 139,1046 'Invalid tile %d in %s' %1047 (id, table_name))1048 finally:1049 gdal.Unlink(tmp_file)1050 else:1051 if not warn_gdal_not_available:1052 warn_gdal_not_available = True1053 self._log('GDAL not available. '1054 'Req 134-139 not tested')1055 def _check_gpkg_extensions(self, c):1056 self._log('Checking gpkg_extensions')1057 c.execute("SELECT 1 FROM sqlite_master WHERE name = 'gpkg_extensions'")1058 if c.fetchone() is None:1059 self._log('... No extensions')1060 return1061 c.execute("PRAGMA table_info(gpkg_extensions)")1062 columns = c.fetchall()1063 expected_columns = [1064 (0, 'table_name', 'TEXT', 0, None, 0),1065 (1, 'column_name', 'TEXT', 0, None, 0),1066 (2, 'extension_name', 'TEXT', 1, None, 0),1067 (3, 'definition', 'TEXT', 1, None, 0),1068 (4, 'scope', 'TEXT', 1, None, 0)]1069 self._check_structure(columns, expected_columns, 58,1070 'gpkg_extensions')1071 c.execute("SELECT table_name, column_name FROM gpkg_extensions WHERE "1072 "table_name IS NOT NULL")1073 rows = c.fetchall()1074 for (table_name, column_name) in rows:1075 # Doesn't work for gpkg_2d_gridded_coverage_ancillary1076 # c.execute("SELECT 1 FROM gpkg_contents WHERE table_name = ?", \1077 # (table_name,) )1078 # ret = c.fetchall()1079 # self._assert(len(ret) == 1, \1080 # 60, ('table_name = %s is registered in ' +\1081 # 'gpkg_extensions, but not in gpkg_contents') % table_name)1082 if column_name is not None:1083 try:1084 c.execute('SELECT %s FROM %s' %1085 (_esc_id(column_name), _esc_id(table_name)))1086 c.fetchone()1087 except:1088 self._assert(False, 61,1089 ("Column %s of table %s mentioned in " +1090 "gpkg_extensions doesn't exist") %1091 (column_name, table_name))1092 c.execute("SELECT extension_name FROM gpkg_extensions")1093 rows = c.fetchall()1094 KNOWN_EXTENSIONS = ['gpkg_rtree_index',1095 'gpkg_zoom_other',1096 'gpkg_webp',1097 'gpkg_metadata',1098 'gpkg_schema',1099 'gpkg_crs_wkt',1100 'gpkg_elevation_tiles']1101 for geom_name in GPKGChecker.EXT_GEOM_TYPES:1102 KNOWN_EXTENSIONS += ['gpkg_geom_' + geom_name]1103 for (extension_name,) in rows:1104 if extension_name.startswith('gpkg_'):1105 self._assert(extension_name in KNOWN_EXTENSIONS,1106 62,1107 "extension_name %s not valid" % extension_name)1108 else:1109 self._assert('_' in extension_name,1110 62,1111 "extension_name %s not valid" % extension_name)1112 author = extension_name[0:extension_name.find('_')]1113 ext_name = extension_name[extension_name.find('_')+1:]1114 for x in author:1115 self._assert((x >= 'a' and x <= 'z') or1116 (x >= 'A' and x <= 'Z') or1117 (x >= '0' and x <= '9'),1118 62,1119 "extension_name %s not valid" %1120 extension_name)1121 for x in ext_name:1122 self._assert((x >= 'a' and x <= 'z') or1123 (x >= 'A' and x <= 'Z') or1124 (x >= '0' and x <= '9') or x == '_',1125 62,1126 "extension_name %s not valid" %1127 extension_name)1128 c.execute("SELECT extension_name, scope FROM gpkg_extensions "1129 "WHERE scope NOT IN ('read-write', 'write-only')")1130 rows = c.fetchall()1131 for (extension_name, scope) in rows:1132 self._assert(False, 64,1133 "extension_name %s has invalid scope %s" %1134 (extension_name, scope))1135 c.execute("SELECT table_name, scope FROM gpkg_extensions "1136 "WHERE extension_name = 'gpkg_rtree_index' ")1137 rows = c.fetchall()1138 for (table_name, scope) in rows:1139 c.execute("SELECT 1 FROM gpkg_contents WHERE lower(table_name) = lower(?) "1140 "AND data_type = 'features'", (table_name,))1141 self._assert(c.fetchone() is not None, 75,1142 ('gpkg_extensions declares gpkg_rtree_index for %s,' +1143 ' but this is not a features table') % table_name)1144 self._assert(scope == 'write-only', 75,1145 'Invalid scope %s for gpkg_rtree_index' % scope)1146 def _check_metadata(self, c):1147 self._log('Checking gpkg_metadata')1148 must_have_gpkg_metadata = False1149 c.execute("SELECT 1 FROM sqlite_master WHERE name = 'gpkg_extensions'")1150 if c.fetchone() is not None:1151 c.execute("SELECT scope FROM gpkg_extensions WHERE "1152 "extension_name = 'gpkg_metadata'")1153 row = c.fetchone()1154 if row is not None:1155 must_have_gpkg_metadata = True1156 (scope, ) = row1157 self._assert(scope == 'read-write', 140,1158 "Wrong scope for gpkg_metadata in "1159 "gpkg_extensions")1160 c.execute("SELECT 1 FROM sqlite_master WHERE name = 'gpkg_metadata'")1161 if c.fetchone() is None:1162 if must_have_gpkg_metadata:1163 self._assert(False, 140, "gpkg_metadata table missing")1164 else:1165 self._log('... No metadata')1166 return1167 c.execute("PRAGMA table_info(gpkg_metadata)")1168 columns = c.fetchall()1169 expected_columns = [1170 (0, 'id', 'INTEGER', 1, None, 1),1171 (1, 'md_scope', 'TEXT', 1, "'dataset'", 0),1172 (2, 'md_standard_uri', 'TEXT', 1, None, 0),1173 (3, 'mime_type', 'TEXT', 1, "'text/xml'", 0),1174 (4, 'metadata', 'TEXT', 1, "''", 0)1175 ]1176 self._check_structure(columns, expected_columns, 93,1177 'gpkg_metadata')1178 c.execute("SELECT 1 FROM sqlite_master "1179 "WHERE name = 'gpkg_metadata_reference'")1180 self._assert(c.fetchone() is not None, 95,1181 "gpkg_metadata_reference is missing")1182 c.execute("PRAGMA table_info(gpkg_metadata_reference)")1183 columns = c.fetchall()1184 expected_columns = [1185 (0, 'reference_scope', 'TEXT', 1, None, 0),1186 (1, 'table_name', 'TEXT', 0, None, 0),1187 (2, 'column_name', 'TEXT', 0, None, 0),1188 (3, 'row_id_value', 'INTEGER', 0, None, 0),1189 (4, 'timestamp', 'DATETIME', 1,1190 "strftime('%Y-%m-%dT%H:%M:%fZ','now')", 0),1191 (5, 'md_file_id', 'INTEGER', 1, None, 0),1192 (6, 'md_parent_id', 'INTEGER', 0, None, 0)1193 ]1194 self._check_structure(columns, expected_columns, 95,1195 'gpkg_metadata_reference')1196 c.execute("SELECT DISTINCT md_scope FROM gpkg_metadata WHERE "1197 "md_scope NOT IN ('undefined', 'fieldSession', "1198 "'collectionSession', 'series', 'dataset', 'featureType', "1199 "'feature', 'attributeType', 'attribute', 'tile', "1200 "'model', 'catalog', 'schema', 'taxonomy', 'software', "1201 "'service', 'collectionHardware', 'nonGeographicDataset', "1202 "'dimensionGroup')")1203 rows = c.fetchall()1204 for (md_scope, ) in rows:1205 self._assert(False, 94, 'Invalid md_scope %s found' % md_scope)1206 c.execute("SELECT DISTINCT reference_scope FROM "1207 "gpkg_metadata_reference WHERE "1208 "reference_scope NOT IN ('geopackage', 'table', "1209 "'column', 'row', 'row/col')")1210 rows = c.fetchall()1211 for (md_scope, ) in rows:1212 self._assert(False, 96,1213 'Invalid reference_scope %s found' % md_scope)1214 c.execute("SELECT table_name FROM "1215 "gpkg_metadata_reference WHERE "1216 "reference_scope = 'geopackage' AND table_name is NOT NULL")1217 rows = c.fetchall()1218 for (table_name, ) in rows:1219 self._assert(False, 97,1220 "row in gpkg_metadata_reference with table_name " +1221 "not null (%s)" % table_name +1222 "but reference_scope = geopackage")1223 c.execute("SELECT table_name FROM "1224 "gpkg_metadata_reference WHERE "1225 "reference_scope != 'geopackage'")1226 rows = c.fetchall()1227 for (table_name, ) in rows:1228 self._assert(table_name is not None, 97,1229 "row in gpkg_metadata_reference with null table_name")1230 c.execute("SELECT 1 FROM gpkg_contents WHERE table_name = ?",1231 (table_name,))1232 self._assert(c.fetchone() is not None, 97,1233 "row in gpkg_metadata_reference with table_name " +1234 "not null (%s) with no reference in " % table_name +1235 "gpkg_contents but reference_scope != geopackage")1236 c.execute("SELECT table_name FROM "1237 "gpkg_metadata_reference WHERE "1238 "reference_scope IN ('geopackage', 'table', 'row') "1239 "AND column_name is NOT NULL")1240 rows = c.fetchall()1241 for (table_name, ) in rows:1242 self._assert(False, 98,1243 "row in gpkg_metadata_reference with column_name " +1244 "not null (table=%s)" % table_name +1245 "but reference_scope = geopackage, table or row")1246 c.execute("SELECT table_name, column_name FROM "1247 "gpkg_metadata_reference WHERE "1248 "reference_scope NOT IN ('geopackage', 'table', 'row')")1249 rows = c.fetchall()1250 for (table_name, column_name) in rows:1251 self._assert(column_name is not None, 98,1252 "row in gpkg_metadata_reference with null "1253 "column_name")1254 try:1255 c.execute("SELECT %s FROM %s" %1256 (_esc_id(column_name), _esc_id(table_name)))1257 except:1258 self._assert(False, 98,1259 "column %s of %s does not exist" %1260 (column_name, table_name))1261 c.execute("SELECT table_name FROM "1262 "gpkg_metadata_reference WHERE "1263 "reference_scope IN ('geopackage', 'table', 'column') "1264 "AND row_id_value is NOT NULL")1265 rows = c.fetchall()1266 for (table_name, ) in rows:1267 self._assert(False, 99,1268 "row in gpkg_metadata_reference with row_id_value " +1269 "not null (table=%s)" % table_name +1270 "but reference_scope = geopackage, table or column")1271 c.execute("SELECT table_name, row_id_value FROM "1272 "gpkg_metadata_reference WHERE "1273 "reference_scope NOT IN ('geopackage', 'table', 'column')")1274 rows = c.fetchall()1275 for (table_name, row_id_value) in rows:1276 self._assert(row_id_value is not None, 99,1277 "row in gpkg_metadata_reference with null "1278 "row_id_value")1279 c.execute("SELECT 1 FROM %s WHERE ROWID = ?" %1280 _esc_id(column_name), (row_id_value, ))1281 self._assert(c.fetchone() is not None, 99,1282 "row %s of %s does not exist" %1283 (str(row_id_value), table_name))1284 c.execute("SELECT timestamp FROM gpkg_metadata_reference")1285 rows = c.fetchall()1286 for (timestamp, ) in rows:1287 try:1288 datetime.datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S.%fZ')1289 except:1290 self._assert(False, 100,1291 ('timestamp = %s in gpkg_metadata_reference' +1292 'is invalid datetime') % (timestamp))1293 c.execute("SELECT md_file_id FROM gpkg_metadata_reference")1294 rows = c.fetchall()1295 for (md_file_id, ) in rows:1296 c.execute("SELECT 1 FROM gpkg_metadata WHERE id = ?",1297 (md_file_id,))1298 self._assert(c.fetchone() is not None, 101,1299 "md_file_id = %s " % str(md_file_id) +1300 "does not have a row in gpkg_metadata")1301 c.execute("SELECT md_parent_id FROM gpkg_metadata_reference "1302 "WHERE md_parent_id IS NOT NULL")1303 rows = c.fetchall()1304 for (md_parent_id, ) in rows:1305 c.execute("SELECT 1 FROM gpkg_metadata WHERE id = ?",1306 (md_parent_id,))1307 self._assert(c.fetchone() is not None, 102,1308 "md_parent_id = %s " % str(md_parent_id) +1309 "does not have a row in gpkg_metadata")1310 c.execute("SELECT md_file_id FROM "1311 "gpkg_metadata_reference WHERE md_parent_id IS NOT NULL "1312 "AND md_file_id = md_parent_id")1313 rows = c.fetchall()1314 for (md_file_id, ) in rows:1315 self._assert(False, 102,1316 "Row with md_file_id = md_parent_id = %s " %1317 str(md_file_id))1318 def check(self):1319 self._assert(os.path.exists(self.filename), None,1320 "%s does not exist" % self.filename)1321 self._assert(self.filename.lower().endswith('.gpkg'), 3,1322 "filename extension isn't .gpkg'")1323 with open(self.filename, 'rb') as f:1324 f.seek(68, 0)1325 application_id = struct.unpack('B' * 4, f.read(4))1326 gp10 = struct.unpack('B' * 4, 'GP10'.encode('ASCII'))1327 gp11 = struct.unpack('B' * 4, 'GP11'.encode('ASCII'))1328 gpkg = struct.unpack('B' * 4, 'GPKG'.encode('ASCII'))1329 self._assert(application_id in (gp10, gp11, gpkg), 2,1330 ("Wrong application_id: %s. " +1331 "Expected one of GP10, GP11, GPKG") %1332 str(application_id))1333 if application_id == gpkg:1334 f.seek(60, 0)1335 user_version = f.read(4)1336 expected_version = 102001337 user_version = struct.unpack('>I', user_version)[0]1338 self._assert(user_version >= expected_version, 2,1339 'Wrong user_version: %d. Expected >= %d' %1340 (user_version, expected_version))1341 conn = sqlite3.connect(':memory:')1342 c = conn.cursor()1343 c.execute('CREATE TABLE foo(one TEXT, two TEXT, '1344 'CONSTRAINT pk PRIMARY KEY (one, two))')1345 c.execute('PRAGMA table_info(foo)')1346 rows = c.fetchall()1347 if rows[1][5] == 2:1348 self.extended_pragma_info = True1349 c.close()1350 conn.close()1351 conn = sqlite3.connect(self.filename)1352 c = conn.cursor()1353 try:1354 try:1355 c.execute('SELECT 1 FROM sqlite_master')1356 c.fetchone()1357 except:1358 self._assert(False, 1, 'not a sqlite3 database')1359 c.execute('PRAGMA foreign_key_check')1360 ret = c.fetchall()1361 self._assert(len(ret) == 0, 7,1362 'foreign_key_check failed: %s' % str(ret))1363 c.execute('PRAGMA integrity_check')1364 self._assert(c.fetchone()[0] == 'ok', 6, 'integrity_check failed')1365 self._check_gpkg_spatial_ref_sys(c)1366 self._check_gpkg_contents(c)1367 self._check_features(c)1368 self._check_tiles(c)1369 self._check_attributes(c)1370 self._check_tiled_gridded_elevation_data(c)1371 self._check_gpkg_extensions(c)1372 self._check_metadata(c)1373 # TODO: check gpkg_schema1374 finally:1375 c.close()1376 conn.close()1377def check(filename, abort_at_first_error=True, verbose=False):1378 checker = GPKGChecker(filename,...
theme.js
Source:theme.js
...416//------------------------------------------------------------------------------417// Button418//------------------------------------------------------------------------------419domapi.Theme.prototype.preDefaults.button = function(arg){420 domapi._assert(arg, "h", domapi.theme.skin.metrics.button.h);421 domapi._assert(arg, "text", "Button" + (domapi.bags.button.length+1));422 domapi._assert(arg, "tabIndex", 1);423 if(!arg["w"])arg["w"] = domapi.textWidth(arg["text"]) + 30;424};425//------------------------------------------------------------------------------426427//------------------------------------------------------------------------------428// Calendar429//------------------------------------------------------------------------------430domapi.Theme.prototype.preDefaults.calendar = function(arg){431 domapi._assert(arg, "w", 155);432 domapi._assert(arg, "h", 158);433 domapi._assert(arg, "value", sysutils.now());434 domapi._assert(arg, "mask", sysutils.defaultDateMask);435 domapi._assert(arg, "doMultiSelect", false); 436 domapi._assert(arg, "mode", "normal"); // or "compact"437 // i tried and tried to get moz to behave, but i can't control the size of it438 // if doborder is allowed to be changed. it's always 3 off, plus it shrinks439 if(domapi.isGecko){440 arg["w"] += 3;441 arg["h"] += 3;442 }443 domapi._assert(arg, "doShowControls", true);444 domapi._assert(arg, "doShowTitle", true);445 domapi._assert(arg, "doShowDays", true);446 if(arg["mode"] == "compact"){447 arg["doShowTitle" ] = false;448 arg["doShowControls"] = false;449 arg["doShowDays" ] = false;450 }451};452//------------------------------------------------------------------------------453domapi.Theme.prototype.postDefaults.calendar = function(arg){454 domapi._assert(arg, "doShowToday", true);455 domapi._assert(arg, "doShowHolidays", true);456 domapi._assert(arg, "tabIndex", 1 );457};458//------------------------------------------------------------------------------459domapi.Theme.prototype.preloadImages.calendar = function(){460 var s = domapi.theme.skin;461 s.calendarLeft = new Image();s.calendarLeft.src = s.path + "calendar/left.gif";462 s.calendarRight = new Image();s.calendarRight.src = s.path + "calendar/right.gif";463};464//------------------------------------------------------------------------------465466//------------------------------------------------------------------------------467// Colorpane468//------------------------------------------------------------------------------469domapi.Theme.prototype.preDefaults.colorpane = function(arg){470 domapi._assert(arg, "w", 225);471 domapi._assert(arg, "h", 350);472 domapi._assert(arg, "value", "#FFFFFF");473 arg.curtainImg = domapi.theme.skin.path + "colorpicker/curtain.png";474 arg.faderImg = domapi.theme.skin.path + "colorpicker/fader.png";475 arg.crosshairImg = domapi.theme.skin.path + "colorpicker/cursor.gif";476 arg.arrowImg = domapi.theme.skin.path + "colorpicker/arrow.gif";477 arg.curtainW = 175;478 arg.curtainH = 187;479 arg.faderW = 10;480 arg.faderH = 187;481 arg.crosshairW = 19;482 arg.crosshairH = 19;483 arg.arrowW = 5;484 arg.arrowH = 9;485};486//------------------------------------------------------------------------------487488//------------------------------------------------------------------------------489// Colorpicker490//------------------------------------------------------------------------------491domapi.Theme.prototype.preDefaults.colorpicker = function(arg){492 domapi._assert(arg, "w", 150);493 domapi._assert(arg, "h", domapi.theme.skin.metrics.dropdown.h);494 domapi._assert(arg, "value", "#FFFFFF");495 domapi._assert(arg, "autoClose", true);496 domapi._assert(arg, "doAllowEdit", true);497 domapi._assert(arg, "tabIndex", 1);498};499//------------------------------------------------------------------------------500501//------------------------------------------------------------------------------502// Combobox503//------------------------------------------------------------------------------504domapi.Theme.prototype.preDefaults.combobox = function(arg){505 domapi._assert(arg, "w", 150);506 domapi._assert(arg, "h", domapi.theme.skin.metrics.dropdown.h);507 domapi._assert(arg, "doAllowEdit", true);508 domapi._assert(arg, "doAutoComplete", false);509 domapi._assert(arg, "tabIndex", 1);510};511//------------------------------------------------------------------------------512513//------------------------------------------------------------------------------514// Combobox2515//------------------------------------------------------------------------------516domapi.Theme.prototype.preDefaults.combobox2 = function(arg){517 domapi._assert(arg, "w", 150);518 domapi._assert(arg, "autoClose", true);519 domapi._assert(arg, "h", domapi.theme.skin.metrics.dropdown.h);520 domapi._assert(arg, "dropdownW", 130);521 domapi._assert(arg, "dropdownH", 150);522 domapi._assert(arg, "allowEdit", true);523 //if(domapi.isGecko)arg["w"] += domapi.theme.border.width * 2;524};525//------------------------------------------------------------------------------526domapi.Theme.prototype.preloadImages.combobox2 = function(){527 var s = domapi.theme.skin;528 s.combobox2 = new Image();s.combobox2.src = s.path + "dropdown/button.gif";529};530//------------------------------------------------------------------------------531532//------------------------------------------------------------------------------533// Datepicker534//------------------------------------------------------------------------------535domapi.Theme.prototype.preDefaults.datepicker = function(arg){536 domapi._assert(arg, "w", 150);537 domapi._assert(arg, "h", domapi.theme.skin.metrics.dropdown.h);538 domapi._assert(arg, "value", sysutils.now());539 domapi._assert(arg, "mask", sysutils.defaultDateMask);540 domapi._assert(arg, "allowEdit", true);541 domapi._assert(arg, "tabIndex", 1);542};543//------------------------------------------------------------------------------544545//------------------------------------------------------------------------------546// Datepicker2547//------------------------------------------------------------------------------548domapi.Theme.prototype.preDefaults.datepicker2 = function(arg){549// domapi._assert(arg, "position", "relative");550 domapi._assert(arg, "w", 120);551 domapi._assert(arg, "imgW", 16);552 domapi._assert(arg, "imgH", 16);553 domapi._assert(arg, "autoClose", true);554 domapi._assert(arg, "src", domapi.theme.skin.path + "datepicker2/picker.gif");555 domapi._assert(arg, "value", sysutils.now());556 domapi._assert(arg, "mask", sysutils.defaultDateMask);557 domapi._assert(arg, "allowEdit", true);558 domapi._assert(arg, "hint", domapi.getString("DATEPICKER2_DROPDOWN"));559};560561//------------------------------------------------------------------------------562// Dropdown563//------------------------------------------------------------------------------564domapi.Theme.prototype.preDefaults.dropdown = function(arg){565 domapi._assert(arg, "w", 130);566 domapi._assert(arg, "h", domapi.theme.skin.metrics.dropdown.h);567 domapi._assert(arg, "tabIndex", 1);568 if(domapi.isGecko)arg["w"] += domapi.theme.border.width * 2;569};570//------------------------------------------------------------------------------571domapi.Theme.prototype.preloadImages.dropdown = function(){572 var s = domapi.theme.skin;573 s.dropdown = new Image();s.dropdown.src = s.path + "form/dropdown.gif";574};575//------------------------------------------------------------------------------576577//------------------------------------------------------------------------------578// Icon579//------------------------------------------------------------------------------580domapi.Theme.prototype.preDefaults.icon = function(arg){581 domapi._assert(arg, "doAllowMove", true);582 domapi._assert(arg, "doDepress", false);583 domapi._assert(arg, "doRollover", false); 584};585586//------------------------------------------------------------------------------587// Imagecheckbox588//------------------------------------------------------------------------------589domapi.Theme.prototype.preDefaults.imagecheckbox = function(arg){590 var m = domapi.theme.skin.metrics.checkbox;591 arg.doBorder = false;592 arg["src" ] = domapi.theme.skin.checkbox.src;593 domapi._assert(arg, "imgW", m.w);594 domapi._assert(arg, "imgH", m.h);595 domapi._assert(arg, "w", 120);596 domapi._assert(arg, "h", m.h);597 domapi._assert(arg, "checkedState", "grayed");598 domapi._assert(arg, "orientation", "horizontal");599 domapi._assert(arg, "index", 0);600 domapi._assert(arg, "tabIndex", 1);601 domapi._assert(arg, "text", "Checkbox" + (domapi.bags.imagecheckbox.length+1));602};603//------------------------------------------------------------------------------604domapi.Theme.prototype.preloadImages.imagecheckbox = function(){605 var s = domapi.theme.skin;606 s["checkbox"] = new Image();s["checkbox"].src = s.path + "form/checkbox.gif";607};608//------------------------------------------------------------------------------609610//------------------------------------------------------------------------------611// Imagelist612//------------------------------------------------------------------------------613domapi.Theme.prototype.preDefaults.imagelist = function(arg){614 domapi._assert(arg, "w", 16);615 domapi._assert(arg, "h", 16);616 domapi._assert(arg, "orientation", "horizontal");617};618//------------------------------------------------------------------------------619620//------------------------------------------------------------------------------621// Imagepagecontrol622//------------------------------------------------------------------------------623domapi.Theme.prototype.postDefaults.imagepagecontrol = function(arg){624 domapi._assert(arg, "orientation", "top" );625 domapi._assert(arg, "overlap", 0);626 domapi._assert(arg, "paneManage", "visibility"); // or display; your choice627};628//------------------------------------------------------------------------------629630//------------------------------------------------------------------------------631// Imageradiobutton632//------------------------------------------------------------------------------633domapi.Theme.prototype.preDefaults.imageradiobutton = function(arg){634 arg.doBorder = false;635 domapi._assert(arg, "imgW", 12);636 domapi._assert(arg, "imgH", 12);637 //domapi._assert(arg, "w", 120); autocalc in unit file638 domapi._assert(arg, "h", 12);639 domapi._assert(arg, "checkedState", "cleared");640 domapi._assert(arg, "orientation", "horizontal");641 domapi._assert(arg, "tabIndex", 1);642 domapi._assert(arg, "text", "Radiobutton" + (domapi.bags.imageradiobutton.length+1));643};644//------------------------------------------------------------------------------645domapi.Theme.prototype.preloadImages.imageradiobutton = function(){646 var s = domapi.theme.skin;647 s["radio"] = new Image();s["radio"].src = s.path + "form/radio.gif"; 648};649//------------------------------------------------------------------------------650651//------------------------------------------------------------------------------652// Imageradiogroup653//------------------------------------------------------------------------------654domapi.Theme.prototype.preDefaults.imageradiogroup = function(arg){655 domapi._assert(arg, "w", 200);656 domapi._assert(arg, "h", 200);657 domapi._assert(arg, "itemIndex", -1);658 domapi._assert(arg, "text", "Radiogroup" + (domapi.bags.imageradiogroup.length+1));659 domapi._assert(arg, "cols", 1);660};661//------------------------------------------------------------------------------662663//------------------------------------------------------------------------------664// Imagetabset665//------------------------------------------------------------------------------666domapi.Theme.prototype.preDefaults.imagetabset = function(arg){667 arg.doBorder = false;668 domapi._assert(arg, "orientation", "horizontal");669 domapi._assert(arg, "overlap", 0);670 domapi._assert(arg, "paneManage", "visibility"); // or display; your choice671};672//------------------------------------------------------------------------------673674//------------------------------------------------------------------------------675// Label676//------------------------------------------------------------------------------677domapi.Theme.prototype.preDefaults.label = function(arg){678 domapi._assert(arg, "doBGFill", false);679 domapi._assert(arg, "doBorder", false);680 domapi._assert(arg, "text", "Label"+(domapi.bags.label.length + 1));681};682//------------------------------------------------------------------------------683684//------------------------------------------------------------------------------685// Listbox686//------------------------------------------------------------------------------687domapi.Theme.prototype.postDefaults.listbox = function(arg){688 domapi._assert(arg, "doHLines", true );689 domapi._assert(arg, "doAllowNoSelect", false);690 domapi._assert(arg, "doShowSelection", true );691 domapi._assert(arg, "doLedger", false);692 domapi._assert(arg, "doAutoWidth", false);693 domapi._assert(arg, "minWidth", 50 );694 domapi._assert(arg, "doMultiSelect", false);695 domapi._assert(arg, "tabIndex", 1 );696};697//------------------------------------------------------------------------------698699//------------------------------------------------------------------------------700// Listgrid701//------------------------------------------------------------------------------702domapi.Theme.prototype.postDefaults.listgrid = function(arg){ 703 var t = domapi.theme;704 domapi._assert(arg, "doLedger", false);705 domapi._assert(arg, "gridlines", 'both');706 domapi._assert(arg, "doShowRowbar", true );707 domapi._assert(arg, "doShowHeader", true );708 domapi._assert(arg, "doMultiSelect", false);709 domapi._assert(arg, "doShowSelection", true );710 domapi._assert(arg, "doAllowNoSelect", false);711 domapi._assert(arg, "doAllowEdit", true );712 domapi._assert(arg, "doColResize", true );713 domapi._assert(arg, "doColMove", true );714 domapi._assert(arg, "doColSort", true );715 domapi._assert(arg, "doDepress", true );716 domapi._assert(arg, "resizeBdr", 10);717 domapi._assert(arg, "minColWidth", 20);718 domapi._assert(arg, "headerH", t.skin.metrics.headerbar.h);719 domapi._assert(arg, "rowbarW", 10);720 domapi._assert(arg, "selectMode", "row");721 domapi._assert(arg, "tabIndex", 1);722 domapi._assert(arg, "doVirtualMode", false); // cannot be changed after creation723};724//------------------------------------------------------------------------------725domapi.Theme.prototype.preloadImages.listgrid = function(){726 var s = domapi.theme.skin;727 s.lg_rowindicator = new Image();s.lg_rowindicator.src = s.path + "listgrid/rowindicator.gif";728 s.lg_rowedit = new Image();s.lg_rowedit.src = s.path + "listgrid/rowedit.gif";729 s.lg_sortup = new Image();s.lg_sortup.src = s.path + "listgrid/sortup.gif";730 s.lg_sortdown = new Image();s.lg_sortdown.src = s.path + "listgrid/sortdown.gif";731};732//------------------------------------------------------------------------------733734735//------------------------------------------------------------------------------736// Menubar737//------------------------------------------------------------------------------738domapi.Theme.prototype.preDefaults.menubar = function(arg){739 domapi._assert(arg, "h", 20);740 domapi._assert(arg, "popupX", 0);741 domapi._assert(arg, "popupY", 0);742};743//------------------------------------------------------------------------------744domapi.Theme.prototype.postDefaults.menubar = function(arg){745 domapi._assert(arg, "doShadow", true);746 domapi._assert(arg, "doImages", true);747};748//------------------------------------------------------------------------------749domapi.Theme.prototype.preloadImages.menubar = function(){750 var s = domapi.theme.skin;751 s.menubarBG = new Image();s.menubarBG.src = s.path + "popupmenu/normal.jpg";752};753//------------------------------------------------------------------------------754755//------------------------------------------------------------------------------756// Notebook757//------------------------------------------------------------------------------758domapi.Theme.prototype.preDefaults.notebook = function(arg){759 domapi._assert(arg, "paneManage", "display"); // or visibility; your choice760 domapi._assert(arg, "doManage", true); // some parents may take over management761};762//------------------------------------------------------------------------------763764//------------------------------------------------------------------------------765// Outlookbar766//------------------------------------------------------------------------------767domapi.Theme.prototype.preDefaults.outlookbar = function(arg){768 domapi._assert(arg, "valign", "justify");769};770//------------------------------------------------------------------------------771domapi.Theme.prototype.preloadImages.outlookbar = function(){772 var s = domapi.theme.skin;773};774//------------------------------------------------------------------------------775776777//------------------------------------------------------------------------------778// Pagecontrol779//------------------------------------------------------------------------------780domapi.Theme.prototype.postDefaults.pagecontrol = function(arg){781 domapi._assert(arg, "orientation", "top" );782 domapi._assert(arg, "tabsetOffset", 0 );783};784//------------------------------------------------------------------------------785786//------------------------------------------------------------------------------787// Popupmenu788//------------------------------------------------------------------------------789domapi.Theme.prototype.preDefaults.popupmenu = function(arg){790 domapi._assert(arg, "doIframeShield", true);791 domapi._assert(arg, "mouseButton", 1);792};793//------------------------------------------------------------------------------794domapi.Theme.prototype.postDefaults.popupmenu = function(arg){795 domapi._assert(arg, "doShadow", true);796 domapi._assert(arg, "doImages", true);797 domapi._assert(arg, "chevron", domapi.isIE?"►":"▶");798};799//------------------------------------------------------------------------------800domapi.Theme.prototype.preloadImages.popupmenu = function(){801 var s = domapi.theme.skin;802 var p = s.path + "popupmenu/";803 s.popupmenuNorm = new Image();s.popupmenuNorm.src = p + "normal.gif";804 s.popupmenuFocus = new Image();s.popupmenuFocus.src = p + "focus.gif";805 s.popupmenuStates = new Image();s.popupmenuStates.src = p + "states.gif";806};807//------------------------------------------------------------------------------808809//------------------------------------------------------------------------------810// Progressbar811//------------------------------------------------------------------------------812domapi.Theme.prototype.preDefaults.progressbar = function(arg){813 domapi._assert(arg, "orientation", "horizontal");814 if(arg.orientation=="vertical"){815 domapi._assert(arg, "w", 16);816 domapi._assert(arg, "h", 143);817 }else{818 domapi._assert(arg, "w", 143);819 domapi._assert(arg, "h", 16);820 }821 domapi._assert(arg, "progress", 0);822 domapi._assert(arg, "max", 100);823 domapi._assert(arg, "quanta", 1);824 arg._paddingCorrection = 6;825};826//------------------------------------------------------------------------------827828//------------------------------------------------------------------------------829// Resizegrip830//------------------------------------------------------------------------------831domapi.Theme.prototype.preDefaults.resizegrip = function(arg){ 832 domapi._assert(arg, "w", 14);833 domapi._assert(arg, "h", 14);834 domapi._assert(arg, "imgW", 12);835 domapi._assert(arg, "imgH", 12);836 domapi._assert(arg, "minW", 24);837 domapi._assert(arg, "minH", 24);838 domapi._assert(arg, "margin",2);839};840//------------------------------------------------------------------------------841domapi.Theme.prototype.preloadImages.resizegrip = function(){842 var s = domapi.theme.skin;843 s.resizegrip = s.path + "resizegrip/resizegrip.gif";844};845//------------------------------------------------------------------------------846847//------------------------------------------------------------------------------848// Rollover849//------------------------------------------------------------------------------850domapi.Theme.prototype.preDefaults.rollover = function(arg){851 domapi._assert(arg, "src", "");852 domapi._assert(arg, "w", 80);853 domapi._assert(arg, "h", 23);854 domapi._assert(arg, "count", 3);855 domapi._assert(arg, "orientation", "horizontal");856};857//------------------------------------------------------------------------------858859//------------------------------------------------------------------------------860// Scrollbar861//------------------------------------------------------------------------------862domapi.Theme.prototype.preloadImages.scrollbar = function(){863 var s = domapi.theme.skin;864 //----------865 s.sb_v_base_bot = new Image();s.sb_v_base_bot.src = s.path + "sb_v_base_bot.gif";866 s.sb_v_base_mid = new Image();s.sb_v_base_mid.src = s.path + "sb_v_base_mid.gif";867 s.sb_v_base_top = new Image();s.sb_v_base_top.src = s.path + "sb_v_base_top.gif";868 s.sb_v_btn_dwn = new Image();s.sb_v_btn_dwn.src = s.path + "sb_v_btn_dwn.gif";869 s.sb_v_btn_up = new Image();s.sb_v_btn_up.src = s.path + "sb_v_btn_up.gif";870 s.sb_v_th_bot = new Image();s.sb_v_th_bot.src = s.path + "sb_v_th_bot.gif";871 s.sb_v_th_mid = new Image();s.sb_v_th_mid.src = s.path + "sb_v_th_mid.gif";872 s.sb_v_th_top = new Image();s.sb_v_th_top.src = s.path + "sb_v_th_top.gif";873 //----------874 s.sb_h_base_bot = new Image();s.sb_h_base_bot.src = s.path + "sb_h_base_bot.gif";875 s.sb_h_base_mid = new Image();s.sb_h_base_mid.src = s.path + "sb_h_base_mid.gif";876 s.sb_h_base_top = new Image();s.sb_h_base_top.src = s.path + "sb_h_base_top.gif";877 s.sb_h_btn_dwn = new Image();s.sb_h_btn_dwn.src = s.path + "sb_h_btn_dwn.gif";878 s.sb_h_btn_up = new Image();s.sb_h_btn_up.src = s.path + "sb_h_btn_up.gif";879 s.sb_h_th_bot = new Image();s.sb_h_th_bot.src = s.path + "sb_h_th_bot.gif";880 s.sb_h_th_mid = new Image();s.sb_h_th_mid.src = s.path + "sb_h_th_mid.gif";881 s.sb_h_th_top = new Image();s.sb_h_th_top.src = s.path + "sb_h_th_top.gif";882};883//------------------------------------------------------------------------------884885//------------------------------------------------------------------------------886887//------------------------------------------------------------------------------888// Scrollbutton889//------------------------------------------------------------------------------890domapi.Theme.prototype.preDefaults.scrollbutton = function(arg){891 domapi._assert(arg, "w", 12);892 domapi._assert(arg, "h", 12);893 domapi._assert(arg, "index", 0);894 domapi._assert(arg, "direction", "top");895};896//------------------------------------------------------------------------------897domapi.Theme.prototype.preloadImages.scrollbutton = function(){898 var s = domapi.theme.skin;899 s["scrollbutton"] = new Image();s["scrollbutton"].src = s.path + "scrollbutton/scrollbutton.gif"; 900};901//------------------------------------------------------------------------------902903//------------------------------------------------------------------------------904// Sidebar905//------------------------------------------------------------------------------906domapi.Theme.prototype.preDefaults.sidebar = function(arg){907 domapi._assert(arg, "doBorder", false);908 domapi._assert(arg, "doAllowAllOpen", true);909 domapi._assert(arg, "doAllowClosing", true);910 domapi._assert(arg, "doAllowHeaderClick", false);911 domapi._assert(arg, "doAllowHeaderDoubleClick", true);912};913//------------------------------------------------------------------------------914domapi.Theme.prototype.preloadImages.sidebar = function(){915 var s = domapi.theme.skin;916 s.sidebarOpen = new Image();s.sidebarOpen.src = s.path + "sidebar/open.gif";917 s.sidebarClose = new Image();s.sidebarClose.src = s.path + "sidebar/close.gif";918};919//------------------------------------------------------------------------------920921//------------------------------------------------------------------------------922// Simplegrid923//------------------------------------------------------------------------------924domapi.Theme.prototype.preDefaults.simplegrid = function(arg){925 domapi._assert(arg, "doBorder", true);926};927//------------------------------------------------------------------------------928929//------------------------------------------------------------------------------930// Slider931//------------------------------------------------------------------------------932domapi.Theme.prototype.preDefaults.slider = function(arg){933 var s = domapi.theme.skin;934 domapi._assert(arg, "w", 150);935 domapi._assert(arg, "h", 37);936 domapi._assert(arg, "thumbW", 11);937 domapi._assert(arg, "thumbH", 21);938 domapi._assert(arg, "mode", "basin");939 domapi._assert(arg, "reversed", false);940 domapi._assert(arg, "bgImg", s.path + "slider/horz_bg.gif");941 domapi._assert(arg, "thumbImg", s.path + "slider/horz_thumb.gif");942 if(!arg["basins"])arg["basins"] = [ [9,6], [15,6], [21,6], [27,6], [33,6], [39,6], [45,6], [51,6], [57,6], [63,6], 943 [69,6], [75,6], [81,6], [87,6], [93,6], [99,6], [105,6], [111,6], [117,6], [123,6],944 [129,6] ];945};946//------------------------------------------------------------------------------947948//------------------------------------------------------------------------------949// Speedbutton950//------------------------------------------------------------------------------951domapi.Theme.prototype.preDefaults.speedbutton = function(arg){952 domapi._assert(arg, "enabled", true);953 domapi._assert(arg, "text", "");954 domapi._assert(arg, "hint", arg["text"]);955 domapi._assert(arg, "orientation", "horizontal");956};957//------------------------------------------------------------------------------958domapi.Theme.prototype.postDefaults.speedbutton = function(arg){959 domapi._assert(arg, "radioGroup", 0);960 // we'll assume the image is 32x16 if not specified.961 // when clipping, the left 16x16 is the normal state, and the right 16x16 is the disabled state.962 // in between are over and down states963 domapi._assert(arg, "imgW", 16);964 domapi._assert(arg, "imgH", 16);965 domapi._assert(arg, "imgOrientation", "horizontal");966 domapi._assert(arg, "doAllowAllUp", false);967 domapi._assert(arg, "down", false);968 domapi._assert(arg, "kind", "button");969 domapi._assert(arg, "dropdownArrow", "▼");970};971//------------------------------------------------------------------------------972973//------------------------------------------------------------------------------974// Spinedit975//------------------------------------------------------------------------------976domapi.Theme.prototype.preDefaults.spinedit = function(arg){977 domapi._assert(arg, "w", 130);978 domapi._assert(arg, "h", domapi.theme.skin.metrics.spinedit.h); 979 domapi._assert(arg, "step", 1);980 domapi._assert(arg, "value", 0);981 domapi._assert(arg, "min", 0);982 domapi._assert(arg, "max", 1000);983 domapi._assert(arg, "doWarning", true);984 domapi._assert(arg, "holdInterval", 500);985 domapi._assert(arg, "revolveInterval", 100);986 if(domapi.isGecko){987 arg["w"] += domapi.theme.border.width * 2;988 arg["h"] += domapi.theme.border.width * 2;989 }990};991//------------------------------------------------------------------------------992domapi.Theme.prototype.preloadImages.spinedit = function(){993 var s = domapi.theme.skin;994 s.spineditUp = new Image();s.spineditUp.src = s.path + "form/spinup.gif";995 s.spineditDown = new Image();s.spineditDown.src = s.path + "form/spindown.gif";996};997//------------------------------------------------------------------------------998999//------------------------------------------------------------------------------1000// Splitpane1001//------------------------------------------------------------------------------1002domapi.Theme.prototype.preDefaults.splitpane = function(arg){1003 domapi._assert(arg, "w", 200);1004 domapi._assert(arg, "h", 200);1005 domapi._assert(arg, "min", 20);1006 domapi._assert(arg, "manageShield", true);1007 domapi._assert(arg, "orientation", "horizontal");1008 domapi._assert(arg, "doHideOnDrag", false);1009 domapi._assert(arg, "doBorder", false);1010 domapi._assert(arg, "doRollover", false);1011 domapi._assert(arg, "doThumbTrack", false); 1012 domapi._assert(arg, "splitterBG", domapi.theme.fonts.buttonface.bgcolor);1013 domapi._assert(arg, "splitterBorderStyle", domapi.theme.border.none);1014 domapi._assert(arg, "splitterW", domapi.theme.skin.metrics.splitter.w);1015};1016//------------------------------------------------------------------------------10171018//------------------------------------------------------------------------------1019// Statusbar1020//------------------------------------------------------------------------------1021domapi.Theme.prototype.preDefaults.statusbar = function(arg){ 1022 domapi._assert(arg, "h", 18);1023 domapi._assert(arg, "margin",2);1024 domapi._assert(arg, "gap", 2);1025};1026//------------------------------------------------------------------------------10271028//------------------------------------------------------------------------------1029// Tabset1030//------------------------------------------------------------------------------1031domapi.Theme.prototype.preDefaults.tabset = function(arg){1032 domapi._assert(arg, "selOffset", 1);1033 domapi._assert(arg, "selFeather", 1);1034 domapi._assert(arg, "tabIndex", 1);1035 domapi._assert(arg, "tabH", domapi.theme.skin.metrics.tab.h);1036 arg["h"] = arg["tabH"] + arg["selOffset"] + 0;1037};1038//------------------------------------------------------------------------------1039domapi.Theme.prototype.postDefaults.tabset = function(arg){1040 domapi._assert(arg, "tabAlign", "left" );1041 domapi._assert(arg, "orientation", "top" );1042 domapi._assert(arg, "doManage", true );1043 domapi._assert(arg, "paneManage", "display"); // or visibility; your choice1044};1045//------------------------------------------------------------------------------1046domapi.Theme.prototype.preloadImages.tabset = function(){1047 var s = domapi.theme.skin;1048 var p = s.path + "tab/";1049 s.tab_TNL = new Image(); s.tab_TNL.src = p + "top_norm_left.gif";1050 s.tab_TNR = new Image(); s.tab_TNR.src = p + "top_norm_right.gif";1051};1052//------------------------------------------------------------------------------10531054//------------------------------------------------------------------------------1055// Toolbar1056//------------------------------------------------------------------------------1057domapi.Theme.prototype.preDefaults.toolbar = function(arg){1058 domapi._assert(arg, "h", 26);1059 domapi._assert(arg, "edgeBorderTop", 3 );1060 domapi._assert(arg, "edgeBorderLeft", 3 );1061 domapi._assert(arg, "spacing", 2 );1062};1063//------------------------------------------------------------------------------10641065//------------------------------------------------------------------------------1066// Tree1067//------------------------------------------------------------------------------1068domapi.Theme.prototype.preDefaults.tree = function(arg){1069 domapi._assert(arg, "w", 150);1070 domapi._assert(arg, "h", 200);1071 domapi._assert(arg, "tabIndex", 1 );1072};1073//------------------------------------------------------------------------------1074domapi.Theme.prototype.postDefaults.tree = function(arg){1075 domapi._assert(arg, "delimiter", "/" );1076 domapi._assert(arg, "doShowLines", false);1077 domapi._assert(arg, "doFolderExpands", true ); // expand nodes on folder click too1078 domapi._assert(arg, "doFolderSelects", true ); // select nodes on folder click too1079 domapi._assert(arg, "doTextExpands", false); // expand nodes on text click too1080 domapi._assert(arg, "doDblClickTextExpands", true ); // expand node on text double-click1081 domapi._assert(arg, "doDblClickFolderExpands",false); // expand node on folder double-click1082};1083//------------------------------------------------------------------------------1084domapi.Theme.prototype.preloadImages.tree = function(){1085 var s = domapi.theme.skin;1086 var p = s.path + "tree/";1087 s.tree_blank = p + "blank.gif";1088 s.tree_folder_opened = p + "folder_opened.gif";1089 s.tree_folder_closed = p + "folder_closed.gif";1090 //----------1091 s.tree_noline_i = p + "noline_i.gif";1092 s.tree_noline_l = p + "noline_l.gif";1093 s.tree_noline_t = p + "noline_t.gif";1094 s.tree_noline_b = p + "noline_b.gif";10951096 s.tree_noline_l_opened = p + "noline_l_opened.gif";1097 s.tree_noline_r_opened = p + "noline_r_opened.gif";1098 s.tree_noline_t_opened = p + "noline_t_opened.gif";1099 s.tree_noline_b_opened = p + "noline_b_opened.gif";11001101 s.tree_noline_l_closed = p + "noline_l_closed.gif";1102 s.tree_noline_r_closed = p + "noline_r_closed.gif";1103 s.tree_noline_t_closed = p + "noline_t_closed.gif";1104 s.tree_noline_b_closed = p + "noline_b_closed.gif";1105 //----------1106 s.tree_lines_i = p + "lines_i.gif";1107 s.tree_lines_l = p + "lines_l.gif";1108 s.tree_lines_t = p + "lines_t.gif";1109 s.tree_lines_b = p + "lines_b.gif";11101111 s.tree_lines_l_opened = p + "lines_l_opened.gif";1112 s.tree_lines_r_opened = p + "lines_r_opened.gif";1113 s.tree_lines_t_opened = p + "lines_t_opened.gif";1114 s.tree_lines_b_opened = p + "lines_b_opened.gif";11151116 s.tree_lines_l_closed = p + "lines_l_closed.gif";1117 s.tree_lines_r_closed = p + "lines_r_closed.gif";1118 s.tree_lines_t_closed = p + "lines_t_closed.gif";1119 s.tree_lines_b_closed = p + "lines_b_closed.gif";1120};1121//------------------------------------------------------------------------------11221123//------------------------------------------------------------------------------1124// Viewbar1125//------------------------------------------------------------------------------1126domapi.Theme.prototype.postDefaults.viewbar = function(arg){1127 domapi._assert(arg, "doShowSelection", true );1128 domapi._assert(arg, "exclusive", true);1129};1130//------------------------------------------------------------------------------11311132//------------------------------------------------------------------------------1133// Window1134//------------------------------------------------------------------------------1135domapi.Theme.prototype.preDefaults.window = function(arg){ 1136 var m = domapi.theme.skin.metrics.window;1137 domapi._assert(arg, "resizeBdr", m.resizeBdr);1138 domapi._assert(arg, "minH", m.minH);1139 domapi._assert(arg, "minW", m.minW);1140 domapi._assert(arg, "minimizedW", m.minimizedW);1141 domapi._assert(arg, "visibleButtons", m.visibleButtons);1142 domapi._assert(arg, "doCreateButtons", m.doCreateButtons);1143 domapi._assert(arg, "btnW", m.btnW);1144 domapi._assert(arg, "btnH", m.btnH);1145 domapi._assert(arg, "titleBarHeight", m.titleBarHeight);1146 domapi._assert(arg, "controlsAlign", m.controlsAlign);1147 domapi._assert(arg, "captionAlign", m.captionAlign);1148 domapi._assert(arg, "titlePadding", m.titlePadding);1149 domapi._assert(arg, "separatorW", m.separatorW);1150 domapi._assert(arg, "doManageFocus", true );1151 domapi._assert(arg, "destroyOnClose", true );1152 domapi._assert(arg, "showContentsWhileDragging", false );1153 domapi._assert(arg, "w", arg["minW"]);1154 domapi._assert(arg, "h", arg["minW"]); // not a typo1155 domapi._assert(arg, "doAllowMove", true );1156 domapi._assert(arg, "doAllowResize", true );1157 domapi._assert(arg, "doManageShield", true );1158 domapi._assert(arg, "doModal", false );1159 domapi._assert(arg, "doIframeShield", true );1160 if(!arg["x"] && !arg["y"])1161 domapi._assert(arg, "position", "relative");1162};1163//------------------------------------------------------------------------------1164domapi.Theme.prototype.postDefaults.window = function(arg){11651166};1167//------------------------------------------------------------------------------1168domapi.Theme.prototype.preloadImages.window = function(){1169 var s = domapi.theme.skin;1170 var p = s.path + "window/";1171 s.window_minimize = p + "minimize.gif";1172 s.window_maximize = p + "maximize.gif";1173 s.window_restore = p + "restore.gif";1174 s.window_close = p + "close.gif";1175 s.window_help = p + "help.gif";
...
JavaScriptFlexBuffersTest.js
Source:JavaScriptFlexBuffersTest.js
...19 {20 const ref = flexbuffers.toReference(new Uint8Array([0, 0, 1]).buffer);21 assert.strictEqual(true, ref.isNull());22 }23 function _assert(object, buffer) {24 assert.deepStrictEqual(flexbuffers.toObject(new Uint8Array(buffer).buffer), object);25 }26 _assert(true, [1, 104, 1]);27 _assert(false, [0, 104, 1]);28 _assert(25, [25, 4, 1]);29 _assert(-25, [231, 4, 1]);30 _assert(230, [230, 8, 1]);31 _assert(230, [230, 0, 5, 2]);32 _assert(-1025, [255, 251, 5, 2]);33 _assert(1025, [1, 4, 9, 2]);34 _assert(2147483647, [255, 255, 255, 127, 6, 4]);35 _assert(-2147483648, [0, 0, 0, 128, 6, 4]);36 _assert(4294967295n, [255, 255, 255, 255, 0, 0, 0, 0, 7, 8]);37 _assert(9223372036854775807n, [255, 255, 255, 255, 255, 255, 255, 127, 7, 8]);38 _assert(-9223372036854775808n, [0, 0, 0, 0, 0, 0, 0, 128, 7, 8]);39 _assert(18446744073709551615n, [255, 255, 255, 255, 255, 255, 255, 255, 11, 8]);40 _assert(4.5, [0, 0, 144, 64, 14, 4]);41 _assert(0.10000000149011612, [205, 204, 204, 61, 14, 4]);42 _assert(0.1, [154, 153, 153, 153, 153, 153, 185, 63, 15, 8]);43 _assert(-1025, [255, 251, 5, 2]);44 _assert("Maxim", [5, 77, 97, 120, 105, 109, 0, 6, 20, 1]);45 _assert("hello ð±", [10, 104, 101, 108, 108, 111, 32, 240, 159, 152, 177, 0, 11, 20, 1]);46 _assert({a:12}, [97, 0, 1, 3, 1, 1, 1, 12, 4, 2, 36, 1]);47 _assert({"":45, "a": 12}, [0, 97, 0, 2, 4, 4, 2, 1, 2, 45, 12, 4, 4, 4, 36, 1]);48}49function testEncode() {50 function _assert(value, buffer) {51 assert.deepStrictEqual(flexbuffers.encode(value), new Uint8Array(buffer));52 }53 _assert(null, [0, 0, 1]);54 _assert(true, [1, 104, 1]);55 _assert(false, [0, 104, 1]);56 _assert(1, [1, 4, 1]);57 _assert(230, [230, 0, 5, 2]);58 _assert(1025, [1, 4, 5, 2]);59 _assert(-1025, [255, 251, 5, 2]);60 _assert(0x100000001, [1, 0, 0, 0, 1, 0, 0, 0, 7, 8]);61 _assert(0.1, [154, 153, 153, 153, 153, 153, 185, 63, 15, 8]);62 _assert(0.5, [0, 0, 0, 63, 14, 4]);63 _assert(new Uint8Array([1, 2, 3]), [3, 1, 2, 3, 3, 100, 1]);64 _assert("Maxim", [5, 77, 97, 120, 105, 109, 0, 6, 20, 1]);65 _assert("hello ð±", [10, 104, 101, 108, 108, 111, 32, 240, 159, 152, 177, 0, 11, 20, 1]);66 _assert([1, 2], [1, 2, 2, 64, 1]);67 _assert([-1, 256], [255, 255, 0, 1, 4, 65, 1]);68 _assert([-45, 256000], [211, 255, 255, 255, 0, 232, 3, 0, 8, 66, 1]);69 _assert([1.1, -256.0], [2, 0, 0, 0, 0, 0, 0, 0, 154, 153, 153, 153, 153, 153, 241, 63, 0, 255, 255, 255, 255, 255, 255, 255, 15, 5, 18, 43, 1]);70 _assert([1, 2, 4], [1, 2, 4, 3, 76, 1]);71 _assert([-1, 256, 4], [255, 255, 0, 1, 4, 0, 6, 77, 1]);72 _assert([[61], 64], [1, 61, 2, 2, 64, 44, 4, 4, 40, 1]);73 _assert(["foo", "bar", "baz"], [3, 102, 111, 111, 0, 3, 98, 97, 114, 0, 3, 98, 97, 122, 0, 3, 15, 11, 7, 3, 60, 1]);74 _assert(["foo", "bar", "baz", "foo", "bar", "baz"], [3, 102, 111, 111, 0, 3, 98, 97, 114, 0, 3, 98, 97, 122, 0, 6, 15, 11, 7, 18, 14, 10, 6, 60, 1]);75 _assert([true, false, true], [3, 1, 0, 1, 3, 144, 1]);76 _assert(['foo', 1, -5, 1.3, true], [77 3, 102, 111, 111, 0, 0, 0, 0,78 5, 0, 0, 0, 0, 0, 0, 0,79 15, 0, 0, 0, 0, 0, 0, 0,80 1, 0, 0, 0, 0, 0, 0, 0,81 251, 255, 255, 255, 255, 255, 255, 255,82 205, 204, 204, 204, 204, 204, 244, 63,83 1, 0, 0, 0, 0, 0, 0, 0,84 20, 4, 4, 15, 104, 45, 43, 185 ]);86 _assert([1, 3.3, 'max', true, null, false], [87 3, 109, 97, 120, 0, 0, 0, 0,88 6, 0, 0, 0, 0, 0, 0, 0,89 1, 0, 0, 0, 0, 0, 0, 0,90 102, 102, 102, 102, 102, 102, 10, 64,91 31, 0, 0, 0, 0, 0, 0, 0,92 1, 0, 0, 0, 0, 0, 0, 0,93 0, 0, 0, 0, 0, 0, 0, 0,94 0, 0, 0, 0, 0, 0, 0, 0,95 4, 15, 20, 104, 0, 104, 54, 43, 196 ]);97 _assert({"a": 12}, [97, 0, 1, 3, 1, 1, 1, 12, 4, 2, 36, 1]);98 _assert({"a": 12, "":45}, [0, 97, 0, 2, 4, 4, 2, 1, 2, 45, 12, 4, 4, 4, 36, 1]);99 // JS currently does not support key vector offset sharing100 _assert([{'something':12}, {'something': 45}], [101 115, 111, 109, 101, 116, 104, 105, 110, 103, 0,102 1, 11, 1, 1, 1, 12, 4, 6, 1, 1, 45, 4, 2, 8, 4, 36, 36, 4, 40, 1103 ]);104}105function testDeduplicationOff() {106 let buffer = flexbuffers.encode([{'something':12}, {'something': 45}], 1, true, true, false);107 assert.deepStrictEqual(buffer, new Uint8Array([108 115, 111, 109, 101, 116, 104, 105, 110, 103,109 0, 1, 11, 1, 1, 1, 12, 4, 1,110 18, 1, 1, 1, 45, 4, 2, 10, 4,111 36, 36, 4, 40, 1112 ]));113 buffer = flexbuffers.encode([{'something':12}, {'something': 45}], 1, true, false, false);114 assert.deepStrictEqual(buffer, new Uint8Array([115 115, 111, 109, 101, 116, 104, 105, 110, 103, 0,116 1, 11, 1, 1, 1, 12, 4, 115, 111, 109,117 101, 116, 104, 105, 110, 103, 0, 1, 11, 1,118 1, 1, 45, 4, 2, 20, 4, 36, 36, 4,119 40, 1120 ]));121 buffer = flexbuffers.encode(['something', 'something', 'dark'], 1, true, false, false);122 assert.deepStrictEqual(buffer, new Uint8Array([123 9, 115, 111, 109, 101, 116, 104,124 105, 110, 103, 0, 4, 100, 97,125 114, 107, 0, 3, 17, 18, 8,126 3, 60, 1127 ]));128 buffer = flexbuffers.encode(['something', 'something', 'dark'], 1, false, false, false);129 assert.deepStrictEqual(buffer, new Uint8Array([130 9, 115, 111, 109, 101, 116, 104, 105, 110,131 103, 0, 9, 115, 111, 109, 101, 116, 104,132 105, 110, 103, 0, 4, 100, 97, 114, 107,133 0, 3, 28, 18, 8, 3, 60, 1134 ]));135}136function testIndirectAdd() {137 function _assertInt(buffer, value, indirect = false, cache = false) {138 const builder = flexbuffers.builder();139 builder.addInt(value, indirect, cache);140 const data = builder.finish();141 assert.deepStrictEqual(data, new Uint8Array(buffer));142 }143 function _assertUInt(buffer, value, indirect = false, cache = false) {144 const builder = flexbuffers.builder();145 builder.addUInt(value, indirect, cache);146 const data = builder.finish();147 assert.deepStrictEqual(data, new Uint8Array(buffer));148 }149 function _assertFloat(buffer, value, indirect = false, cache = false) {150 const builder = flexbuffers.builder();151 builder.addFloat(value, indirect, cache);152 const data = builder.finish();153 assert.deepStrictEqual(data, new Uint8Array(buffer));154 }155 _assertInt([0, 4, 1], 0);156 _assertInt([0, 1, 24, 1], 0, true);157 _assertInt([255, 0, 5, 2], 255);158 _assertUInt([0, 8, 1], 0);159 _assertUInt([0, 1, 28, 1], 0, true);160 _assertUInt([255, 8, 1], 255);161 _assertUInt([185, 115, 175, 118, 250, 84, 8, 0, 11, 8], 2345234523452345);162 _assertUInt([185, 115, 175, 118, 250, 84, 8, 0, 8, 31, 1], 2345234523452345, true);163 _assertInt([185, 115, 175, 118, 250, 84, 8, 0, 7, 8], 2345234523452345);164 _assertInt([185, 115, 175, 118, 250, 84, 8, 0, 8, 27, 1], 2345234523452345, true);165 _assertFloat([154, 153, 153, 153, 153, 153, 185, 63, 15, 8], 0.1);166 _assertFloat([154, 153, 153, 153, 153, 153, 185, 63, 8, 35, 1], 0.1, true);167 _assertFloat([0, 0, 0, 0, 14, 4], 0);168 _assertFloat([0, 0, 0, 0, 4, 34, 1], 0, true);169}170function testIndirectWithCache() {171 function _assertInt(buffer, values) {172 const builder = flexbuffers.builder();173 builder.startVector();174 values.forEach(v => {175 builder.addInt(v, true, true)176 });177 builder.end();178 const data = builder.finish();179 assert.deepStrictEqual(data, new Uint8Array(buffer));180 }181 function _assertUInt(buffer, values) {182 const builder = flexbuffers.builder();183 builder.startVector();184 values.forEach(v => {185 builder.addUInt(v, true, true);186 });187 builder.end();188 const data = builder.finish();189 assert.deepStrictEqual(data, new Uint8Array(buffer));190 }191 function _assertFloat(buffer, values) {192 const builder = flexbuffers.builder();193 builder.startVector();194 values.forEach(v => {195 builder.addFloat(v, true, true);196 });197 builder.end();198 const data = builder.finish();199 assert.deepStrictEqual(data, new Uint8Array(buffer));200 }201 _assertInt(202 [185, 115, 175, 118, 250, 84, 8, 0, 4, 9, 10, 11, 12, 27, 27, 27, 27, 8, 40, 1],203 [2345234523452345, 2345234523452345, 2345234523452345, 2345234523452345]204 );205 _assertUInt(206 [185, 115, 175, 118, 250, 84, 8, 0, 4, 9, 10, 11, 12, 31, 31, 31, 31, 8, 40, 1],207 [2345234523452345, 2345234523452345, 2345234523452345, 2345234523452345]208 );209 _assertFloat(210 [154, 153, 153, 153, 153, 153, 185, 63, 4, 9, 10, 11, 12, 35, 35, 35, 35, 8, 40, 1],211 [0.1, 0.1, 0.1, 0.1]212 );213}214function testMapBuilder() {215 const builder = flexbuffers.builder();216 builder.startMap();217 builder.addKey('a');218 builder.add(12);219 builder.addKey('');220 builder.add(45);221 builder.end();222 const data = builder.finish();223 assert.deepStrictEqual(data, new Uint8Array([97, 0, 0, 2, 2, 5, 2, 1, 2, 45, 12, 4, 4, 4, 36, 1]));224}225function testRoundTrip() {226 const example = {227 "age": 35,228 "flags": [true, false, true, true],229 "weight": 72.5,230 "name": "Maxim",231 "address": {232 "city": "Bla",233 "zip": "12345",234 "countryCode": "XX",235 }236 };237 function _assert(value) {238 let buffer = flexbuffers.encode(value, 1);239 let o = flexbuffers.toObject(buffer.buffer);240 assert.deepStrictEqual(o, value);241 }242 _assert(example);243 _assert(0x100000001n);244}245function testRoundTripWithBuilder() {246 const example = {247 "age": 35,248 "flags": [true, false, true, true],249 "weight": 72.5,250 "name": "Maxim",251 "address": {252 "city": "Bla",253 "zip": "12345",254 "countryCode": "XX",255 }256 };257 const builder = flexbuffers.builder();...
aqua.js
Source:aqua.js
...50}51domapi.Theme.prototype.preDefaults.imagecheckbox = function(arg){52 arg.doBorder = false;53 arg["src" ] = domapi.theme.skin.checkbox.src;54 domapi._assert(arg, "imgW", 15);55 domapi._assert(arg, "imgH", 16);56 domapi._assert(arg, "w", 200);57 domapi._assert(arg, "h", 16);58 domapi._assert(arg, "checkedState", "grayed");59 domapi._assert(arg, "orientation", "horizontal");60 domapi._assert(arg, "index", 0);61 domapi._assert(arg, "tabIndex", 1);62 domapi._assert(arg, "text", "Checkbox" + (domapi.bags.imagecheckbox.length+1));63};64domapi.Theme.prototype.preDefaults.imageradiobutton = function(arg){65 arg.doBorder = false;66 domapi._assert(arg, "imgW", 14);67 domapi._assert(arg, "imgH", 15);68 //domapi._assert(arg, "w", 200);69 domapi._assert(arg, "h", 15);70 domapi._assert(arg, "checkedState", "cleared");71 domapi._assert(arg, "orientation", "horizontal");72 domapi._assert(arg, "index", 0);73 domapi._assert(arg, "tabIndex", 1);74 domapi._assert(arg, "text", "Radiobutton" + (domapi.bags.imageradiobutton.length+1));75};76domapi.Theme.prototype.postDefaults.pagecontrol = function(arg){77 domapi._assert(arg, "orientation", "top" );78 domapi._assert(arg, "tabsetOffset", 10 );79};80domapi.Theme.prototype.preDefaults.popupmenu = function(arg){81 domapi._assert(arg, "doIframeShield", true);82 domapi.comps.popupmenu._draw = function(){83 this.setAlpha(90);84 this.popupmenuDraw();85 };86};87domapi.Theme.prototype.postDefaults.popupmenu = function(arg){88 domapi._assert(arg, "doShadow", true);89 domapi._assert(arg, "doImages", true);90 domapi._assert(arg, "chevron", '►'); 91};92domapi.Theme.prototype.preDefaults.progressbar = function(arg){93 domapi._assert(arg, "orientation", "horizontal");94 if(arg.orientation=="vertical"){95 domapi._assert(arg, "w", 18);96 domapi._assert(arg, "h", 143);97 }else{98 domapi._assert(arg, "w", 143);99 domapi._assert(arg, "h", 18);100 }101 domapi._assert(arg, "progress", 0);102 domapi._assert(arg, "max", 100);103 domapi._assert(arg, "quanta", 1);104 arg._paddingCorrection = 0;105};106domapi.Theme.prototype.preDefaults.resizegrip = function(arg){ 107 domapi._assert(arg, "w", 13);108 domapi._assert(arg, "h", 13);109 domapi._assert(arg, "imgW", 11);110 domapi._assert(arg, "imgH", 11);111 domapi._assert(arg, "minW", 24);112 domapi._assert(arg, "minH", 24);113 domapi._assert(arg, "margin",2);114};115domapi.Theme.prototype.preDefaults.slider = function(arg){116 var s = domapi.theme.skin;117 domapi._assert(arg, "w", 150);118 domapi._assert(arg, "h", 37);119 domapi._assert(arg, "thumbW", 15);120 domapi._assert(arg, "thumbH", 16);121 domapi._assert(arg, "mode", "basin");122 domapi._assert(arg, "reversed", false);123 domapi._assert(arg, "bgImg", s.path + "slider/horz_bg.gif");124 domapi._assert(arg, "thumbImg", s.path + "slider/horz_thumb.gif");125 if(!arg["basins"])arg["basins"] = [ [9,9], [15,9], [21,9], [27,9], [33,9], [39,9], [45,9], [51,9], [57,9], [63,9], 126 [69,9], [75,9], [81,9], [87,9], [93,9], [99,9], [105,9], [111,9], [117,9], [123,9],127 [129,9] ];128};129domapi.Theme.prototype.preDefaults.tabset = function(arg){130 domapi._assert(arg, "selOffset", 1);131 domapi._assert(arg, "selFeather", 0);132 domapi._assert(arg, "tabH", 22);133 domapi._assert(arg, "tabIndex", 1);134 domapi._assert(arg, "tabAlign", "center");135};136//------------------------------------------------------------------------------137
...
proto.py
Source:proto.py
2from cspace.dht.util import checkAddr34class ProtocolError(Exception) : pass56def _assert( cond, msg=None ) :7 if not cond :8 if msg is None : msg = 'invalid message data'9 raise ProtocolError, msg1011def validatePingRequest( msg ) :12 _assert( len(msg) == 0 )13 return msg1415def validatePingResponse( msg ) :16 _assert( type(msg) is str )17 _assert( len(msg) == 0 )18 return msg1920def validateGetAddrRequest( msg ) :21 _assert( len(msg) == 0 )22 return msg2324def validateGetAddrResponse( msg ) :25 _assert( type(msg) is list )26 msg = tuple(msg)27 _assert( checkAddr(msg) )28 return msg2930def validateGetKeyRequest( msg ) :31 _assert( len(msg) == 1 )32 _assert( type(msg[0]) is str )33 return msg3435def validateGetKeyResponse( msg ) :36 _assert( type(msg) is list )37 _assert( len(msg) == 4 )38 result,data,updateLevel,signature = msg39 _assert( type(result) is int )40 _assert( type(data) is str )41 _assert( type(updateLevel) is int )42 _assert( updateLevel >= 0 )43 _assert( type(signature) is str )44 return msg4546def validatePutKeyRequest( msg ) :47 _assert( len(msg) == 4 )48 publicKeyData,data,updateLevel,signature = msg49 _assert( type(publicKeyData) is str )50 _assert( type(data) is str )51 _assert( type(updateLevel) is int )52 _assert( updateLevel > 0 )53 _assert( type(signature) is str )54 return msg5556def validatePutKeyResponse( msg ) :57 _assert( type(msg) is list )58 _assert( len(msg) == 4 )59 result,data,updateLevel,signature = msg60 _assert( type(result) is int )61 _assert( type(data) is str )62 _assert( type(updateLevel) is int )63 _assert( updateLevel >= 0 )64 _assert( type(signature) is str )65 return msg6667def validateFindNodesRequest( msg ) :68 _assert( len(msg) == 1 )69 _assert( type(msg[0]) is str )70 _assert( len(msg[0]) == DHT_ID_LENGTH )71 return msg7273def validateFindNodesResponse( msg ) :74 _assert( type(msg) is list )75 msg = msg[:DHT_K]76 out = []77 for x in msg :78 _assert( type(x) is list )79 x = tuple(x)80 _assert( checkAddr(x) )81 out.append( x )82 return out8384def validateFirewallCheckRequest( msg ) :85 _assert( len(msg) == 2 )86 addr = tuple( msg )87 _assert( checkAddr(addr) )88 return addr8990def validateFirewallCheckResponse( msg ) :91 _assert( type(msg) is list )92 fwResult,token = msg93 _assert( type(fwResult) is int )94 _assert( type(token) is str )95 return msg9697MESSAGES = ( 'Ping', 'GetAddr', 'GetKey', 'PutKey', 'FindNodes', 'FirewallCheck' )98requestValidators = {}99responseValidators = {}100def _initTables() :101 g = globals()102 for m in MESSAGES :103 requestValidators[m] = g[ 'validate' + m + 'Request' ]104 responseValidators[m] = g[ 'validate' + m + 'Response' ]105_initTables()106107def validateRequest( msg ) :108 _assert( type(msg) is list )109 _assert( len(msg) >= 2 )110 cmd, useSourceAddr = msg[0], msg[1]111 del msg[:2]112 _assert( type(cmd) is str )113 _assert( type(useSourceAddr) is int )114 _assert( useSourceAddr in (0,1) )115 validator = requestValidators.get( cmd )116 _assert( validator is not None )117 msg = validator( msg )118 return (cmd, useSourceAddr, msg)119120def validateResponse( cmd, msg ) :121 validator = responseValidators[cmd]
...
fileproto.py
Source:fileproto.py
...1516_badPathElements = ('','.','..')1718def _validateDirPath( p ) :19 _assert( p.find('\\') == -1 )20 elems = p.split( '/' )21 _assert( len(elems) >= 2 )22 _assert( elems[0] == elems[-1] == '' )23 del elems[0]24 for x in elems[:-1] :25 _assert( x not in _badPathElements )26 return elems2728def _validateFilePath( p ) :29 _assert( p.find('\\') == -1 )30 elems = p.split( '/' )31 _assert( len(elems) >= 2 )32 _assert( elems[0] == '' )33 del elems[0]34 for x in elems :35 _assert( x not in _badPathElements )36 return elems3738def _validateEntry( f ) :39 s = len( f )40 _assert( s > 0 )41 isDir = f[-1] == '/'42 if isDir :43 dirName = f[:-1]44 _assert( dirName not in _badPathElements )45 _assert( dirName.find('/') == -1 )46 _assert( dirName.find('\\') == -1 )47 else :48 _assert( f not in _badPathElements )49 _assert( f.find('/') == -1 )50 _assert( f.find('\\') == -1 )5152def _vResponseHeader( msg, size ) :53 _assert( type(msg) is ListType )54 _assert( len(msg) == size )55 err = msg[0]56 _assert( type(err) is IntType )57 _assert( err >= 0 )5859def _assert( cond, msg='protocol error' ) :60 if not cond :61 raise ProtocolError, msg6263def _vListRequest( msg ) :64 _assert( len(msg) == 1 )65 _assert( type(msg[0]) is StringType )66 pathElements = _validateDirPath( msg[0] )67 return pathElements6869def _vListResponse( msg ) :70 _vResponseHeader( msg, 2 )71 ls = msg[1]72 _assert( type(ls) is ListType )73 for x in ls :74 _assert( type(x) is StringType )75 _validateEntry( x )76 return msg7778def _vGetSizeRequest( msg ) :79 _assert( len(msg) == 1 )80 _assert( type(msg[0]) is StringType )81 pathElements = _validateFilePath( msg[0] )82 return pathElements8384def _vGetSizeResponse( msg ) :85 _vResponseHeader( msg, 2 )86 size = msg[1]87 _assert( type(size) is IntType )88 _assert( size >= 0 )89 return msg9091def _vReadRequest( msg ) :92 _assert( len(msg) == 3 )93 path, offset, size = msg94 _assert( type(path) is StringType )95 pathElements = _validateFilePath( path )96 _assert( (type(offset) is IntType) and (offset >= 0) )97 _assert( (type(size) is IntType) and (size > 0) )98 return [ pathElements, offset, size ]99100def _vReadResponse( msg ) :101 _vResponseHeader( msg, 2 )102 data = msg[1]103 _assert( type(data) is StringType )104 return msg105106_validators = {}107_validators['List'] = (_vListRequest,_vListResponse)108_validators['GetSize'] = (_vGetSizeRequest,_vGetSizeResponse)109_validators['Read'] = (_vReadRequest,_vReadResponse)110111def validateRequest( msg ) :112 _assert( type(msg) is ListType )113 _assert( len(msg) >= 1 )114 cmd = msg[0]115 args = msg[1:]116 _assert( type(cmd) is StringType )117 validator = _validators.get( cmd, (None,None) )[0]118 _assert( validator is not None )119 args = validator( args )120 return (cmd,args)121122def validateResponse( cmd, msg ) :123 validator = _validators.get( cmd, (None,None) )[1]124 _assert( validator is not None )
...
Using AI Code Generation
1var wpt = require('webpagetest');2var _assert = wpt._assert;3var options = {4};5var test = wpt.test(options, function(err, data) {6 if (err) {7 _assert(false, err);8 } else {9 _assert(true, 'Test completed');10 }11});12MIT © [Rohit Sharma](
Using AI Code Generation
1var _assert = require("wpt")._assert;2var assert = require("wpt").assert;3var _equal = require("wpt")._equal;4var equal = require("wpt").equal;5var _notEqual = require("wpt")._notEqual;6var notEqual = require("wpt").notEqual;7var _deepEqual = require("wpt")._deepEqual;8var deepEqual = require("wpt").deepEqual;9var _notDeepEqual = require("wpt")._notDeepEqual;10var notDeepEqual = require("wpt").notDeepEqual;11var _strictEqual = require("wpt")._strictEqual;12var strictEqual = require("wpt").strictEqual;13var _notStrictEqual = require("wpt")._notStrictEqual;14var notStrictEqual = require("wpt").notStrictEqual;15var _throws = require("wpt")._throws;16var throws = require("wpt").throws;17var _doesNotThrow = require("wpt")._doesNotThrow;18var doesNotThrow = require("wpt").doesNotThrow;19var _ifError = require("wpt")._ifError;20var ifError = require("wpt").ifError;21var _ok = require("wpt")._ok;
Using AI Code Generation
1wpt._assert(true, "This is a message");2wpt._assert(false, "This is a message");3wpt._assert(true, "This is a message");4wpt._assert(false, "This is a message");5wpt._assert(true, "This is a message");6wpt._assert(false, "This is a message");7wpt._assert(true, "This is a message");8wpt._assert(false, "This is a message");9wpt._assert(true, "This is a message");10wpt._assert(false, "This is a message");11wpt._assert(true, "This is a message");12wpt._assert(false, "This is a message");13wpt._assert(true, "This is a message");14wpt._assert(false, "This is a message");15wpt._assert(true, "This is a message");16wpt._assert(false, "This is a message");17wpt._assert(true, "This is a message");18wpt._assert(false, "This is a message");19wpt._assert(true, "This is a message
Using AI Code Generation
1var wpt = require('wpt');2var _assert = wpt._assert;3var assert = require('assert');4describe('wpt._assert', function() {5 it('should throw error if first argument is not a string', function() {6 assert.throws(function() {7 _assert(123, 'test');8 }, Error);9 });10 it('should throw error if second argument is not a string', function() {11 assert.throws(function() {12 _assert('test', 123);13 }, Error);14 });15 it('should not throw error if both arguments are strings', function() {16 assert.doesNotThrow(function() {17 _assert('test', 'test');18 }, Error);19 });20});21describe('wpt.getLocations', function() {22 it('should return an array of locations', function() {23 wpt.getLocations(function(err, data) {24 assert.equal(err, null);25 assert.equal(data.statusCode, 200);26 });27 });28});29describe('wpt.getTesters', function() {30 it('should return an array of testers', function() {31 wpt.getTesters(function(err, data) {32 assert.equal(err, null);33 assert.equal(data.statusCode, 200);34 });35 });36});37describe('wpt.getTest', function() {38 it('should return an object of test', function() {39 wpt.getTest('140618_9K_7b6c0f8a3d6a0e6e7b6c8f6a8e6d9f6a', function(err, data) {40 assert.equal(err, null);41 assert.equal(data.statusCode, 200);42 });43 });44});45describe('wpt.getTestResults', function() {46 it('should return an object of test results', function() {47 wpt.getTestResults('140618_9K_7b6c0f8a3d6a0e6e7b6c8f6a8e6d9f6a', function(err, data) {48 assert.equal(err, null);
Using AI Code Generation
1var wptest = require('./wptest.js');2wptest._assert(true, 'This is a test message');3wptest._assert(false, 'This is a test message');4module.exports = {5 _assert: function(value, message) {6 if (!value) {7 throw new Error('Assertion failed: ' + message);8 }9 }10};11var wptest = require('./wptest.js');12wptest._assert(true, 'This is a test message');13wptest._assert(false, 'This is a test message');14module.exports = {15 _assert: function(value, message) {16 if (!value) {17 throw new Error('Assertion failed: ' + message);18 }19 }20};21var wptest = require('./wptest.js');22wptest._assert(true, 'This is a test message');23wptest._assert(false, 'This is a test message');24module.exports = {25 _assert: function(value, message) {26 if (!value) {27 throw new Error('Assertion failed: ' + message);28 }29 }30};31var wptest = require('./wptest.js');32wptest._assert(true, 'This is a test message');33wptest._assert(false, 'This is a test message');34module.exports = {35 _assert: function(value, message) {36 if (!value) {37 throw new Error('Assertion failed: ' + message);38 }39 }40};41var wptest = require('./wptest.js');42wptest._assert(true, 'This is a test message');43wptest._assert(false, 'This is a test message');44module.exports = {45 _assert: function(value, message) {46 if (!value) {47 throw new Error('Assertion failed: ' + message);48 }49 }50};
Using AI Code Generation
1var assert = require('assert');2assert( 1 == 2, "1 is not equal to 2" );3var nodeunit = require('nodeunit');4nodeunit.assert( 1 == 2, "1 is not equal to 2" );5var assert = require('assert');6assert( 1 == 2, "1 is not equal to 2" );7var nodeunit = require('nodeunit');8nodeunit.assert( 1 == 2, "1 is not equal to 2" );9var assert = require('assert');10assert( 1 == 2, "1 is not equal to 2" );11var nodeunit = require('nodeunit');12nodeunit.assert( 1 == 2, "1 is not equal to 2" );13var assert = require('assert');14assert( 1 == 2, "1 is not equal to 2" );15var nodeunit = require('nodeunit');16nodeunit.assert( 1 == 2, "1 is not equal to 2" );17var assert = require('assert');18assert( 1 == 2, "1 is not equal to 2" );19var nodeunit = require('nodeunit');20nodeunit.assert( 1 == 2, "1 is not equal to 2" );21var assert = require('assert');22assert( 1 == 2, "1 is not equal to 2" );23var nodeunit = require('nodeunit');24nodeunit.assert( 1 == 2, "1 is not equal to 2" );
Using AI Code Generation
1var wpt = require('wpt');2var assert = wpt.assert;3var test = wpt.test;4test('Test Case 1', function() {5 assert.equal(1, 1, '1 is equal to 1');6});7test('Test Case 2', function() {8 assert.equal(1, 2, '1 is not equal to 2');9});10test('Test Case 3', function() {11 assert.equal(1, 3, '1 is not equal to 3');12});13test('Test Case 4', function() {14 assert.equal(1, 4, '1 is not equal to 4');15});16test('Test Case 5', function() {17 assert.equal(1, 5, '1 is not equal to 5');18});19test('Test Case 6', function() {20 assert.equal(1, 6, '1 is not equal to 6');21});22test('Test Case 7', function() {23 assert.equal(1, 7, '1 is not equal to 7');24});25test('Test Case 8', function() {26 assert.equal(1, 8, '1 is not equal to 8');27});28test('Test Case 9', function() {29 assert.equal(1, 9, '1 is not equal to 9');30});31test('Test Case 10', function() {32 assert.equal(1, 10, '1 is not equal to 10');33});34test('Test Case 11', function() {35 assert.equal(1, 11, '1 is not equal to 11');36});37test('Test Case 12', function() {38 assert.equal(1, 12, '1 is not equal to 12');39});40test('Test Case 13', function() {41 assert.equal(1, 13, '1 is not equal to 13');42});43test('Test Case 14', function() {44 assert.equal(1, 14, '1 is not equal to 14');45});46test('Test Case 15', function() {47 assert.equal(1, 15, '1 is not equal to 15');48});49test('Test Case 16', function() {50 assert.equal(1, 16, '1 is not equal to 16');51});52test('Test Case 17', function() {
Using AI Code Generation
1var wpt = require('wpt');2wpt._assert(true, "This is a test");3wpt._assert(false, "This is a test");4var wpt = require('wpt');5wpt._assert(true, "This is a test");6wpt._assert(false, "This is a test");7var wpt = require('wpt');8wpt._assert(true, "This is a test");9wpt._assert(false, "This is a test");10var wpt = require('wpt');11wpt._assert(true, "This is a test");12wpt._assert(false, "This is a test");13var wpt = require('wpt');14wpt._assert(true, "This is a test");15wpt._assert(false, "This is a test");16var wpt = require('wpt');17wpt._assert(true, "This is a test");18wpt._assert(false, "This is a test");19var wpt = require('wpt');20wpt._assert(true, "This is a test");21wpt._assert(false, "This is a test");22var wpt = require('wpt');23wpt._assert(true, "This is a test");
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!