Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for computeSchemaChecksum #3733

Merged
merged 13 commits into from
Jun 10, 2022
3 changes: 1 addition & 2 deletions core/backend/src/test/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import * as path from "path";
import { IModelJsNative, NativeLoggerCategory } from "@bentley/imodeljs-native";
import { IModelJsNative, NativeLibrary, NativeLoggerCategory } from "@bentley/imodeljs-native";
import { BentleyLoggerCategory, IDisposable, Logger, LogLevel, ProcessDetector } from "@itwin/core-bentley";
import { BackendLoggerCategory } from "../BackendLoggerCategory";
import { IModelHost, IModelHostConfiguration } from "../IModelHost";
Expand Down Expand Up @@ -103,4 +103,3 @@ before(async () => {
after(async () => {
await TestUtils.shutdownBackend();
});

kabentley marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ECSchema schemaName="SchemaA" alias="a" version="1.1.1" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2" displayLabel="SchemaA" description="This is a test Schema.">
<ECSchemaReference name="SchemaC" version="3.3.3" alias="c"/>
<ECSchemaReference name="SchemaB" version="2.2.2" alias="b"/>
</ECSchema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ECSchema schemaName="SchemaB" alias="b" version="2.2.3" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2" displayLabel="SchemaB" description="This is a test Schema.">
<ECSchemaReference name="SchemaC" version="3.3.3" alias="c"/>
<ECSchemaReference name="SchemaD" version="4.4.4" alias="d"/>
</ECSchema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ECSchema schemaName="SchemaC" alias="c" version="3.3.4" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2" displayLabel="SchemaC" description="This is a test Schema.">
<ECSchemaReference name="SchemaD" version="4.4.4" alias="d"/>
</ECSchema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<ECSchema schemaName="SchemaD" alias="d" version="4.4.4" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2" displayLabel="SchemaD" description="This is a test Schema.">
</ECSchema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ECSchema schemaName="SchemaB" alias="b" version="2.2.2" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2" displayLabel="SchemaB" description="This is a test Schema.">
<ECSchemaReference name="SchemaC" version="3.3.3" alias="c"/>
<ECSchemaReference name="SchemaD" version="4.4.4" alias="d"/>
</ECSchema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ECSchema schemaName="SchemaC" alias="c" version="3.3.3" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2" displayLabel="SchemaC" description="This is a test Schema.">
<ECSchemaReference name="SchemaD" version="4.4.4" alias="d"/>
</ECSchema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<ECSchema schemaName="SchemaD" alias="d" version="4.4.4" xmlns="http://www.bentley.com/schemas/Bentley.ECXML.3.2" displayLabel="SchemaD" description="This is a test Schema.">
</ECSchema>
36 changes: 36 additions & 0 deletions core/backend/src/test/native/ECSchemaOps.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { assert } from "chai";
import * as path from "path";
import { IModelHost } from "../../core-backend";
import { KnownTestLocations } from "../KnownTestLocations";

describe("ECSchemaOps", () => {
let assetsDir: string;

beforeEach(async () => {
assetsDir = path.join(KnownTestLocations.assetsDir, "ECSchemaOps");
});

afterEach(async () => {
});

it("computeChecksum", async () => {
const schemaPath = path.join(assetsDir, "SchemaA.ecschema.xml");
const refPath = path.dirname(schemaPath);
const sha1 = IModelHost.platform.computeSchemaChecksum(schemaPath, [refPath]);
assert.isDefined(sha1);
assert.equal(sha1, "3ac6578060902aa0b8426b61d62045fdf7fa0b2b", "Expected sha1 hash values to match");
});

it("computeChecksumWithExactRefMatch", async () => {
const schemaPath = path.join(assetsDir, "SchemaA.ecschema.xml");
let refPath = path.dirname(schemaPath);
refPath = path.join(refPath, "exact-match");
const sha1 = IModelHost.platform.computeSchemaChecksumWithExactRefMatch(schemaPath, [refPath]);
assert.isDefined(sha1);
assert.equal(sha1, "2a618664fbba1df7c05f27d7c0e8f58de250003b", "Expected sha1 hash values to match");
});
});