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

Fix key and registry tests to work on Windows 10 #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 38 additions & 9 deletions test/key.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global describe, it */
/* global describe, it, before */
'use strict';
require('./test_helper');
var assert = require('assert'),
Expand All @@ -7,34 +7,47 @@ var assert = require('assert'),

describe('Key Open Tests', () => {
it('Should create a key given a subkey', () => {
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_READ);
assert(key.handle !== null && key.handle !== undefined);
key.close();
});

it('Should open a subkey provided a previously opened key', () => {
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '', windef.KEY_ACCESS.KEY_ALL_ACCESS);
var key2 = key.openSubKey('.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '', windef.KEY_ACCESS.KEY_READ);
var key2 = key.openSubKey('.txt', windef.KEY_ACCESS.KEY_READ);
assert(key2.handle !== null && key2.handle !== undefined);
key.close();
key2.close();
});

it('Should properly close', () => {
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_READ);
key.close();

// ensure that the key is actually closed by trying to open a subkey
// which should fail
assert.throws(() => {
key.openSubKey('OpenWithList', windef.KEY_ACCESS.KEY_ALL_ACCESS);
key.openSubKey('OpenWithList', windef.KEY_ACCESS.KEY_READ);
});
});
});

describe('Create Key Tests', function () {
before(() => {
// We perform all testing that modifies the registry under HKCU\Software\windows-registry-node.
// Ensure this exists.
var key = new Key(windef.HKEY.HKEY_CURRENT_USER, 'Software', windef.KEY_ACCESS.KEY_READ);
try {
key.createSubKey('windows-registry-node', windef.KEY_ACCESS.KEY_ALL_ACCESS);
}
catch (error) {
console.log('Error creating test environment root key');
throw error;
}
});

it('Should create a new key and Delete it', () => {
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
var key = new Key(windef.HKEY.HKEY_CURRENT_USER, 'Software\\windows-registry-node', windef.KEY_ACCESS.KEY_ALL_ACCESS);

assert(key.handle !== undefined);
assert(key.handle !== null);
Expand All @@ -46,8 +59,9 @@ describe('Create Key Tests', function () {
assert(createdKey.path === '\test_key_name');

createdKey.deleteKey();

assert.throws(() => {
key.openSubKey('\test_key_name', windef.KEY_ACCESS.KEY_ALL_ACCESS);
key.openSubKey('\test_key_name', windef.KEY_ACCESS.KEY_READ);
}, (err) => {
assert(err.indexOf('ERROR_FILE_NOT_FOUND') > -1);
return true;
Expand All @@ -58,8 +72,21 @@ describe('Create Key Tests', function () {
});

describe('Set / Query Value Tests', function () {
before(() => {
// We perform all testing that modifies the registry under HKCU\Software\windows-registry-node.
// Ensure this exists.
var key = new Key(windef.HKEY.HKEY_CURRENT_USER, 'Software', windef.KEY_ACCESS.KEY_READ);
try {
key.createSubKey('windows-registry-node', windef.KEY_ACCESS.KEY_ALL_ACCESS);
}
catch (error) {
console.log('Error creating test environment root key');
throw error;
}
});

it('Should set and read REG_SZ Value', () => {
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
var key = new Key(windef.HKEY.HKEY_CURRENT_USER, 'Software\\windows-registry-node', windef.KEY_ACCESS.KEY_ALL_ACCESS);

assert(key.handle !== null && key.handle !== undefined);

Expand All @@ -68,6 +95,8 @@ describe('Set / Query Value Tests', function () {
var value = key.getValue('test_value_name');

assert.equal(value, 'test_value');

key.deleteValue('test_value_name');
key.close();
});
});
43 changes: 34 additions & 9 deletions test/registry.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global describe, it */
/* global describe, it, before */
'use strict';
require('./test_helper');

Expand All @@ -8,22 +8,34 @@ var assert = require('assert'),

describe('Registry API open tests', () => {
it('Should open a subkey provided a predefined key', () => {
var key = registry.openKeyFromPredefined(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
console.log(key.handle);
var key = registry.openKeyFromPredefined(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_READ);
assert.equal(key.handle !== null, true);
key.close();
});
it('Should open a subkey provided a previously opened key', () => {
var key = registry.openKeyFromPredefined(windef.HKEY.HKEY_CLASSES_ROOT, '', windef.KEY_ACCESS.KEY_ALL_ACCESS);
var key2 = registry.openKeyFromKeyObject(key, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
var key = registry.openKeyFromPredefined(windef.HKEY.HKEY_CLASSES_ROOT, '', windef.KEY_ACCESS.KEY_READ);
var key2 = registry.openKeyFromKeyObject(key, '.txt', windef.KEY_ACCESS.KEY_READ);
assert.equal(key2.handle !== null, true);
key.close();
});
});

describe('Create Key Tests', function () {
before(() => {
// We perform all testing that modifies the registry under HKCU\Software\windows-registry-node.
// Ensure this exists.
var key = registry.openKeyFromPredefined(windef.HKEY.HKEY_CURRENT_USER, 'Software', windef.KEY_ACCESS.KEY_READ);
try {
registry.createKey(key, 'windows-registry-node', windef.KEY_ACCESS.KEY_ALL_ACCESS);
}
catch (error) {
console.log('Error creating test environment root key');
throw error;
}
});

it('Should create a new key and delete it', () => {
var key = registry.openKeyFromPredefined(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
var key = registry.openKeyFromPredefined(windef.HKEY.HKEY_CURRENT_USER, 'Software\\windows-registry-node', windef.KEY_ACCESS.KEY_ALL_ACCESS);

assert(key.handle !== undefined);
assert(key.handle !== null);
Expand All @@ -49,17 +61,30 @@ describe('Create Key Tests', function () {
});

describe('Set / Query Value Tests', function () {
before(() => {
// We perform all testing that modifies the registry under HKCU\Software\windows-registry-node.
// Ensure this exists.
var key = registry.openKeyFromPredefined(windef.HKEY.HKEY_CURRENT_USER, 'Software', windef.KEY_ACCESS.KEY_READ);
try {
registry.createKey(key, 'windows-registry-node', windef.KEY_ACCESS.KEY_ALL_ACCESS);
}
catch (error) {
console.log('Error creating test environment root key');
throw error;
}
});

it('Should set and read REG_SZ Value', () => {
var key = registry.openKeyFromPredefined(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
var key = registry.openKeyFromPredefined(windef.HKEY.HKEY_CURRENT_USER, 'Software\\windows-registry-node', windef.KEY_ACCESS.KEY_ALL_ACCESS);

assert.equal(key.handle !== null, true);

registry.setValueForKeyObject(key, 'test_value_name', windef.REG_VALUE_TYPE.REG_SZ, 'test_value');

var value = registry.queryValueForKeyObject(key, 'test_value_name');
console.log('her is value:' + value);
assert.equal(value, 'test_value');
console.log('lngth:' + value.length);

registry.deleteValue(key, 'test_value_name');
key.close();
});
});