Skip to content

Commit

Permalink
Clean up some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Sneath committed May 2, 2022
1 parent 66b3c22 commit 640c6fb
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 20 deletions.
6 changes: 3 additions & 3 deletions example/bluetoothle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ void main() {
});

for (final path in devicePaths) {
final pathPtr = TEXT(path);
final hDevice = CreateFile(pathPtr.cast(), 0,
FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, NULL);
final pathPtr = path.toNativeUtf16();
final hDevice = CreateFile(pathPtr, 0, FILE_SHARE_READ | FILE_SHARE_WRITE,
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hDevice == INVALID_HANDLE_VALUE) {
final error = GetLastError();
print('CreateFile - Get Device Handle error: $error');
Expand Down
3 changes: 3 additions & 0 deletions test/console_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ void main() {
final outputHandle = GetStdHandle(STD_OUTPUT_HANDLE);
expect(outputHandle, isNot(INVALID_HANDLE_VALUE));
});

test('GetStdHandle() with invalid handle', () {
final outputHandle = GetStdHandle(0xFFFF);
expect(outputHandle, equals(INVALID_HANDLE_VALUE));
Expand All @@ -32,6 +33,8 @@ void main() {
expect(bufferInfo.ref.dwCursorPosition.Y,
lessThanOrEqualTo(bufferInfo.ref.dwSize.Y));
}

free(bufferInfo);
});

test('SHGetKnownFolderPath', () {
Expand Down
2 changes: 1 addition & 1 deletion test/devices_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:win32/win32.dart';

void main() {
test('Volume management API', () {
final volumeNamePtr = calloc<Uint16>(MAX_PATH).cast<Utf16>();
final volumeNamePtr = wsalloc(MAX_PATH);

final hFindVolume = FindFirstVolume(volumeNamePtr, MAX_PATH);
expect(hFindVolume, isNot(INVALID_HANDLE_VALUE));
Expand Down
9 changes: 5 additions & 4 deletions test/neutrality_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import 'package:win32/win32.dart';
// least one test is run successfully.)
void main() {
test('Dormant package does not cause failures on other platforms', () {
final point = calloc<POINT>().ref
..x = 0x10
..y = 0x7F;
expect(point.x + point.y, equals(0x8F));
final point = calloc<POINT>()
..ref.x = 0x10
..ref.y = 0x7F;
expect(point.ref.x + point.ref.y, equals(0x8F));
free(point);
});
}
16 changes: 9 additions & 7 deletions test/union_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ const VK_A = 0x41;

void main() {
test('Anonymous nested unions work', () {
final kbd = calloc<INPUT>();
kbd.ref.type = INPUT_KEYBOARD;
kbd.ref.ki.wVk = VK_A;
kbd.ref.ki.dwFlags = KEYEVENTF_KEYUP;
final kbd = calloc<INPUT>()
..ref.type = INPUT_KEYBOARD
..ref.ki.wVk = VK_A
..ref.ki.dwFlags = KEYEVENTF_KEYUP;

expect(kbd.ref.ki.wVk, equals(VK_A));

kbd.ref.ki.wVk = 0;
kbd.ref.ki.wScan = 0x20AC; // euro sign
kbd.ref.ki.dwFlags = KEYEVENTF_UNICODE;
kbd
..ref.ki.wVk = 0
..ref.ki.wScan = 0x20AC // euro sign
..ref.ki.dwFlags = KEYEVENTF_UNICODE;

expect(kbd.ref.type, equals(INPUT_KEYBOARD));
expect(kbd.ref.ki.wVk, isZero);
expect(kbd.ref.ki.dwFlags, equals(KEYEVENTF_UNICODE));

free(kbd);
});
}
15 changes: 10 additions & 5 deletions test/window_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,26 @@ void main() {
final outputHandle = GetModuleHandle(nullptr);
expect(outputHandle, isNot(0));
});

test('RegisterClass()', () {
final hInstance = GetModuleHandle(nullptr);

final CLASS_NAME = TEXT('CLASS_NAME');
final pClassName = 'CLASS_NAME'.toNativeUtf16();

final wc = calloc<WNDCLASS>()
..ref.style = CS_HREDRAW | CS_VREDRAW
..ref.lpfnWndProc = Pointer.fromFunction<WindowProc>(MainWindowProc, 0)
..ref.hInstance = hInstance
..ref.lpszClassName = CLASS_NAME
..ref.lpszClassName = pClassName
..ref.hCursor = LoadCursor(NULL, IDC_ARROW)
..ref.hbrBackground = GetStockObject(WHITE_BRUSH);

final result = RegisterClass(wc);

expect(result, isNot(0));
try {
final result = RegisterClass(wc);
expect(result, isNot(0));
} finally {
free(pClassName);
free(wc);
}
});
}
6 changes: 6 additions & 0 deletions test/winrt_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ void main() {

test('WinRT double initialization should succeed with warning', () {
final hr = RoInitialize(RO_INIT_TYPE.RO_INIT_MULTITHREADED);
expect(SUCCEEDED(hr), isTrue);
expect(hr, equals(S_OK));

final hr2 = RoInitialize(RO_INIT_TYPE.RO_INIT_MULTITHREADED);
expect(SUCCEEDED(hr2), isTrue);
expect(hr2, equals(S_FALSE));

// Balance out uninitialization. This is deliberately called twice.
Expand All @@ -25,11 +27,15 @@ void main() {

test('WinRT change of threading model should fail', () {
final hr = RoInitialize(RO_INIT_TYPE.RO_INIT_MULTITHREADED);
expect(SUCCEEDED(hr), isTrue);
expect(hr, equals(S_OK));

final hr2 = RoInitialize(RO_INIT_TYPE.RO_INIT_SINGLETHREADED);
expect(FAILED(hr2), isTrue);
expect(hr2, equals(RPC_E_CHANGED_MODE));

// Balance out uninitialization. This is deliberately only called once,
// because it only succeeded once.
RoUninitialize();
});

Expand Down

0 comments on commit 640c6fb

Please sign in to comment.