RegressionTests__Win32OperatingSystemTest.st
author "Patrik Svestka <patrik.svestka@gmail.com>"
Fri, 16 Dec 2022 10:44:49 +0100
branchjv
changeset 2608 b77fda6a2e98
parent 2607 ddf2eb8b3f1d
parent 2606 ca1a3083168c
permissions -rwxr-xr-x
Merge - commit more robust tests - commit fixes random test fails when creating a process

"{ Encoding: utf8 }"

"
 COPYRIGHT (c) Claus Gittinger / eXept Software AG
 COPYRIGHT (c) 2016 Jan Vrany
 COPYRIGHT (c) 2021 svestkap
 COPYRIGHT (c) 2021-2022 Patrik Svestka
 COPYRIGHT (c) 2022 Jan Vrany
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ Package: 'stx:goodies/regression' }"

"{ NameSpace: RegressionTests }"

TestCase subclass:#Win32OperatingSystemTest
	instanceVariableNames:'registryPath windowsDetailsRegistryPath'
	classVariableNames:''
	poolDictionaries:''
	category:'tests-Regression-RuntimeSystem'
!

!Win32OperatingSystemTest class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) Claus Gittinger / eXept Software AG
 COPYRIGHT (c) 2016 Jan Vrany
 COPYRIGHT (c) 2021 svestkap
 COPYRIGHT (c) 2021 Patrik Svestka
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
! !

!Win32OperatingSystemTest methodsFor:'file templates'!

unicodeRegistryExample

^  'Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\%1]
@="しか OMG"
"emptyToTest"=""
"testEmptyMultiSZ"=hex(7):00,00
"bledesu"="''Testing Unicode chars ř ž č ルすしかき'').          "
"しかき    "="Testus gradus"
" ř ž č ル.          "="Testing Unicode chars ř ž č ルすしかき"
"zero"=hex:
"non-zero"=hex:11,10
"す    "=hex:10
"dword_value"=dword:000023af
"11"="A number name"
"き"=dword:234234af
"qwordvalue"=hex(b):ad,61,28,a3,95,0e,74,79
"qword_max"=hex(b):ff,ff,ff,ff,ff,ff,ff,ff
"すし"=hex(b):ef,ad,00,00,00,00,00,00
"Font_Leelawadee UI Bold"=hex(7):53,00,45,00,47,00,4f,00,45,00,55,00,49,00,42,\
  00,2e,00,54,00,54,00,46,00,2c,00,53,00,65,00,67,00,6f,00,65,00,20,00,55,00,\
  49,00,20,00,42,00,6f,00,6c,00,64,00,2c,00,31,00,31,00,30,00,2c,00,38,00,32,\
  00,00,00,53,00,45,00,47,00,4f,00,45,00,55,00,49,00,42,00,2e,00,54,00,54,00,\
  46,00,2c,00,53,00,65,00,67,00,6f,00,65,00,20,00,55,00,49,00,20,00,42,00,6f,\
  00,6c,00,64,00,00,00,4d,00,45,00,49,00,52,00,59,00,4f,00,42,00,2e,00,54,00,\
  54,00,43,00,2c,00,4d,00,65,00,69,00,72,00,79,00,6f,00,20,00,55,00,49,00,20,\
  00,42,00,6f,00,6c,00,64,00,2c,00,31,00,32,00,30,00,2c,00,39,00,36,00,00,00,\
  4d,00,45,00,49,00,52,00,59,00,4f,00,42,00,2e,00,54,00,54,00,43,00,2c,00,4d,\
  00,65,00,69,00,72,00,79,00,6f,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,\
  64,00,00,00,4d,00,53,00,4a,00,48,00,42,00,44,00,2e,00,54,00,54,00,43,00,2c,\
  00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,4a,00,68,00,\
  65,00,6e,00,67,00,48,00,65,00,69,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,\
  00,64,00,2c,00,31,00,32,00,30,00,2c,00,39,00,36,00,00,00,4d,00,53,00,4a,00,\
  48,00,42,00,44,00,2e,00,54,00,54,00,43,00,2c,00,4d,00,69,00,63,00,72,00,6f,\
  00,73,00,6f,00,66,00,74,00,20,00,4a,00,68,00,65,00,6e,00,67,00,48,00,65,00,\
  69,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,00,00,4d,00,53,00,59,\
  00,48,00,42,00,44,00,2e,00,54,00,54,00,43,00,2c,00,4d,00,69,00,63,00,72,00,\
  6f,00,73,00,6f,00,66,00,74,00,20,00,59,00,61,00,48,00,65,00,69,00,20,00,55,\
  00,49,00,20,00,42,00,6f,00,6c,00,64,00,2c,00,31,00,32,00,38,00,2c,00,39,00,\
  36,00,00,00,4d,00,53,00,59,00,48,00,42,00,44,00,2e,00,54,00,54,00,43,00,2c,\
  00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,59,00,61,00,\
  48,00,65,00,69,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,00,00,4d,\
  00,41,00,4c,00,47,00,55,00,4e,00,42,00,44,00,2e,00,54,00,54,00,46,00,2c,00,\
  4d,00,61,00,6c,00,67,00,75,00,6e,00,20,00,47,00,6f,00,74,00,68,00,69,00,63,\
  00,20,00,42,00,6f,00,6c,00,64,00,2c,00,31,00,31,00,38,00,2c,00,39,00,36,00,\
  00,00,4d,00,41,00,4c,00,47,00,55,00,4e,00,42,00,44,00,2e,00,54,00,54,00,46,\
  00,2c,00,4d,00,61,00,6c,00,67,00,75,00,6e,00,20,00,47,00,6f,00,74,00,68,00,\
  69,00,63,00,20,00,42,00,6f,00,6c,00,64,00,00,00,59,00,55,00,47,00,4f,00,54,\
  00,48,00,42,00,2e,00,54,00,54,00,43,00,2c,00,59,00,75,00,20,00,47,00,6f,00,\
  74,00,68,00,69,00,63,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,2c,\
  00,31,00,32,00,38,00,2c,00,39,00,36,00,00,00,59,00,55,00,47,00,4f,00,54,00,\
  48,00,42,00,2e,00,54,00,54,00,43,00,2c,00,59,00,75,00,20,00,47,00,6f,00,74,\
  00,68,00,69,00,63,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,00,00,\
  53,00,45,00,47,00,55,00,49,00,53,00,59,00,4d,00,2e,00,54,00,54,00,46,00,2c,\
  00,53,00,65,00,67,00,6f,00,65,00,20,00,55,00,49,00,20,00,53,00,79,00,6d,00,\
  62,00,6f,00,6c,00,00,00,00,00
"ř ž č ルすしか"=hex(7):27,00,54,00,65,00,73,00,74,00,69,00,6e,00,67,00,20,00,55,\
  00,6e,00,69,00,63,00,6f,00,64,00,65,00,20,00,63,00,68,00,61,00,72,00,73,00,\
  20,00,59,01,20,00,7e,01,20,00,0d,01,20,00,eb,30,59,30,57,30,4b,30,4d,30,27,\
  00,29,00,00,00,53,00,45,00,47,00,4f,00,45,00,55,00,49,00,42,00,2e,00,54,00,\
  54,00,46,00,2c,00,53,00,65,00,67,00,6f,00,65,00,20,00,55,00,49,00,20,00,42,\
  00,6f,00,6c,00,64,00,2c,00,31,00,31,00,30,00,2c,00,38,00,32,00,00,00,53,00,\
  45,00,47,00,4f,00,45,00,55,00,49,00,42,00,2e,00,54,00,54,00,46,00,2c,00,53,\
  00,65,00,67,00,6f,00,65,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,\
  00,00,4d,00,45,00,49,00,52,00,59,00,4f,00,42,00,2e,00,54,00,54,00,43,00,2c,\
  00,4d,00,65,00,69,00,72,00,79,00,6f,00,20,00,55,00,49,00,20,00,42,00,6f,00,\
  6c,00,64,00,2c,00,31,00,32,00,30,00,2c,00,39,00,36,00,00,00,4d,00,45,00,49,\
  00,52,00,59,00,4f,00,42,00,2e,00,54,00,54,00,43,00,2c,00,4d,00,65,00,69,00,\
  72,00,79,00,6f,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,00,00,4d,\
  00,53,00,4a,00,48,00,42,00,44,00,2e,00,54,00,54,00,43,00,2c,00,4d,00,69,00,\
  63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,4a,00,68,00,65,00,6e,00,67,\
  00,48,00,65,00,69,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,2c,00,\
  31,00,32,00,30,00,2c,00,39,00,36,00,00,00,4d,00,53,00,4a,00,48,00,42,00,44,\
  00,2e,00,54,00,54,00,43,00,2c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,\
  66,00,74,00,20,00,4a,00,68,00,65,00,6e,00,67,00,48,00,65,00,69,00,20,00,55,\
  00,49,00,20,00,42,00,6f,00,6c,00,64,00,00,00,4d,00,53,00,59,00,48,00,42,00,\
  44,00,2e,00,54,00,54,00,43,00,2c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,\
  00,66,00,74,00,20,00,59,00,61,00,48,00,65,00,69,00,20,00,55,00,49,00,20,00,\
  42,00,6f,00,6c,00,64,00,2c,00,31,00,32,00,38,00,2c,00,39,00,36,00,00,00,4d,\
  00,53,00,59,00,48,00,42,00,44,00,2e,00,54,00,54,00,43,00,2c,00,4d,00,69,00,\
  63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,59,00,61,00,48,00,65,00,69,\
  00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,00,00,4d,00,41,00,4c,00,\
  47,00,55,00,4e,00,42,00,44,00,2e,00,54,00,54,00,46,00,2c,00,4d,00,61,00,6c,\
  00,67,00,75,00,6e,00,20,00,47,00,6f,00,74,00,68,00,69,00,63,00,20,00,42,00,\
  6f,00,6c,00,64,00,2c,00,31,00,31,00,38,00,2c,00,39,00,36,00,00,00,4d,00,41,\
  00,4c,00,47,00,55,00,4e,00,42,00,44,00,2e,00,54,00,54,00,46,00,2c,00,4d,00,\
  61,00,6c,00,67,00,75,00,6e,00,20,00,47,00,6f,00,74,00,68,00,69,00,63,00,20,\
  00,42,00,6f,00,6c,00,64,00,00,00,59,00,55,00,47,00,4f,00,54,00,48,00,42,00,\
  2e,00,54,00,54,00,43,00,2c,00,59,00,75,00,20,00,47,00,6f,00,74,00,68,00,69,\
  00,63,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,2c,00,31,00,32,00,\
  38,00,2c,00,39,00,36,00,00,00,59,00,55,00,47,00,4f,00,54,00,48,00,42,00,2e,\
  00,54,00,54,00,43,00,2c,00,59,00,75,00,20,00,47,00,6f,00,74,00,68,00,69,00,\
  63,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,00,00,53,00,45,00,47,\
  00,55,00,49,00,53,00,59,00,4d,00,2e,00,54,00,54,00,46,00,2c,00,53,00,65,00,\
  67,00,6f,00,65,00,20,00,55,00,49,00,20,00,53,00,79,00,6d,00,62,00,6f,00,6c,\
  00,00,00,00,00
"Ugh"=hex(2):27,00,54,00,65,00,73,00,74,00,69,00,6e,00,67,00,20,00,55,00,6e,00,\
  69,00,63,00,6f,00,64,00,65,00,20,00,63,00,68,00,61,00,72,00,73,00,20,00,59,\
  01,20,00,7e,01,20,00,0d,01,20,00,eb,30,59,30,57,30,4b,30,4d,30,27,00,29,00,\
  2e,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,00,00
" č ルすしか"=hex(2):27,00,54,00,65,00,73,00,74,00,69,00,6e,00,67,00,20,00,55,00,\
  6e,00,69,00,63,00,6f,00,64,00,65,00,20,00,63,00,68,00,61,00,72,00,73,00,20,\
  00,59,01,20,00,7e,01,20,00,0d,01,20,00,eb,30,59,30,57,30,4b,30,4d,30,27,00,\
  29,00,2e,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,00,\
  00
[HKEY_CURRENT_USER\Software\%1\ ルすしか_empty]

[HKEY_CURRENT_USER\Software\%1\ ルすしか]
"bledesu"="''Testing Unicode chars ř ž č ルすしかき'').          "
"しかき    "="Testus gradus"
" ř ž č ル.          "="Testing Unicode chars ř ž č ルすしかき"
"zero"=hex:
"non-zero"=hex:11,10
"す    "=hex:10
"dword_value"=dword:000023af
"き"=dword:234234af
"qwordvalue"=hex(b):ad,61,28,a3,95,0e,74,79
"qword_max"=hex(b):ff,ff,ff,ff,ff,ff,ff,ff
"すし"=hex(b):ef,ad,00,00,00,00,00,00
"Font_Leelawadee UI Bold"=hex(7):53,00,45,00,47,00,4f,00,45,00,55,00,49,00,42,\
  00,2e,00,54,00,54,00,46,00,2c,00,53,00,65,00,67,00,6f,00,65,00,20,00,55,00,\
  49,00,20,00,42,00,6f,00,6c,00,64,00,2c,00,31,00,31,00,30,00,2c,00,38,00,32,\
  00,00,00,53,00,45,00,47,00,4f,00,45,00,55,00,49,00,42,00,2e,00,54,00,54,00,\
  46,00,2c,00,53,00,65,00,67,00,6f,00,65,00,20,00,55,00,49,00,20,00,42,00,6f,\
  00,6c,00,64,00,00,00,4d,00,45,00,49,00,52,00,59,00,4f,00,42,00,2e,00,54,00,\
  54,00,43,00,2c,00,4d,00,65,00,69,00,72,00,79,00,6f,00,20,00,55,00,49,00,20,\
  00,42,00,6f,00,6c,00,64,00,2c,00,31,00,32,00,30,00,2c,00,39,00,36,00,00,00,\
  4d,00,45,00,49,00,52,00,59,00,4f,00,42,00,2e,00,54,00,54,00,43,00,2c,00,4d,\
  00,65,00,69,00,72,00,79,00,6f,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,\
  64,00,00,00,4d,00,53,00,4a,00,48,00,42,00,44,00,2e,00,54,00,54,00,43,00,2c,\
  00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,4a,00,68,00,\
  65,00,6e,00,67,00,48,00,65,00,69,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,\
  00,64,00,2c,00,31,00,32,00,30,00,2c,00,39,00,36,00,00,00,4d,00,53,00,4a,00,\
  48,00,42,00,44,00,2e,00,54,00,54,00,43,00,2c,00,4d,00,69,00,63,00,72,00,6f,\
  00,73,00,6f,00,66,00,74,00,20,00,4a,00,68,00,65,00,6e,00,67,00,48,00,65,00,\
  69,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,00,00,4d,00,53,00,59,\
  00,48,00,42,00,44,00,2e,00,54,00,54,00,43,00,2c,00,4d,00,69,00,63,00,72,00,\
  6f,00,73,00,6f,00,66,00,74,00,20,00,59,00,61,00,48,00,65,00,69,00,20,00,55,\
  00,49,00,20,00,42,00,6f,00,6c,00,64,00,2c,00,31,00,32,00,38,00,2c,00,39,00,\
  36,00,00,00,4d,00,53,00,59,00,48,00,42,00,44,00,2e,00,54,00,54,00,43,00,2c,\
  00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,59,00,61,00,\
  48,00,65,00,69,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,00,00,4d,\
  00,41,00,4c,00,47,00,55,00,4e,00,42,00,44,00,2e,00,54,00,54,00,46,00,2c,00,\
  4d,00,61,00,6c,00,67,00,75,00,6e,00,20,00,47,00,6f,00,74,00,68,00,69,00,63,\
  00,20,00,42,00,6f,00,6c,00,64,00,2c,00,31,00,31,00,38,00,2c,00,39,00,36,00,\
  00,00,4d,00,41,00,4c,00,47,00,55,00,4e,00,42,00,44,00,2e,00,54,00,54,00,46,\
  00,2c,00,4d,00,61,00,6c,00,67,00,75,00,6e,00,20,00,47,00,6f,00,74,00,68,00,\
  69,00,63,00,20,00,42,00,6f,00,6c,00,64,00,00,00,59,00,55,00,47,00,4f,00,54,\
  00,48,00,42,00,2e,00,54,00,54,00,43,00,2c,00,59,00,75,00,20,00,47,00,6f,00,\
  74,00,68,00,69,00,63,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,2c,\
  00,31,00,32,00,38,00,2c,00,39,00,36,00,00,00,59,00,55,00,47,00,4f,00,54,00,\
  48,00,42,00,2e,00,54,00,54,00,43,00,2c,00,59,00,75,00,20,00,47,00,6f,00,74,\
  00,68,00,69,00,63,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,00,00,\
  53,00,45,00,47,00,55,00,49,00,53,00,59,00,4d,00,2e,00,54,00,54,00,46,00,2c,\
  00,53,00,65,00,67,00,6f,00,65,00,20,00,55,00,49,00,20,00,53,00,79,00,6d,00,\
  62,00,6f,00,6c,00,00,00,00,00
"ř ž č ルすしか"=hex(7):27,00,54,00,65,00,73,00,74,00,69,00,6e,00,67,00,20,00,55,\
  00,6e,00,69,00,63,00,6f,00,64,00,65,00,20,00,63,00,68,00,61,00,72,00,73,00,\
  20,00,59,01,20,00,7e,01,20,00,0d,01,20,00,eb,30,59,30,57,30,4b,30,4d,30,27,\
  00,29,00,00,00,53,00,45,00,47,00,4f,00,45,00,55,00,49,00,42,00,2e,00,54,00,\
  54,00,46,00,2c,00,53,00,65,00,67,00,6f,00,65,00,20,00,55,00,49,00,20,00,42,\
  00,6f,00,6c,00,64,00,2c,00,31,00,31,00,30,00,2c,00,38,00,32,00,00,00,53,00,\
  45,00,47,00,4f,00,45,00,55,00,49,00,42,00,2e,00,54,00,54,00,46,00,2c,00,53,\
  00,65,00,67,00,6f,00,65,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,\
  00,00,4d,00,45,00,49,00,52,00,59,00,4f,00,42,00,2e,00,54,00,54,00,43,00,2c,\
  00,4d,00,65,00,69,00,72,00,79,00,6f,00,20,00,55,00,49,00,20,00,42,00,6f,00,\
  6c,00,64,00,2c,00,31,00,32,00,30,00,2c,00,39,00,36,00,00,00,4d,00,45,00,49,\
  00,52,00,59,00,4f,00,42,00,2e,00,54,00,54,00,43,00,2c,00,4d,00,65,00,69,00,\
  72,00,79,00,6f,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,00,00,4d,\
  00,53,00,4a,00,48,00,42,00,44,00,2e,00,54,00,54,00,43,00,2c,00,4d,00,69,00,\
  63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,4a,00,68,00,65,00,6e,00,67,\
  00,48,00,65,00,69,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,2c,00,\
  31,00,32,00,30,00,2c,00,39,00,36,00,00,00,4d,00,53,00,4a,00,48,00,42,00,44,\
  00,2e,00,54,00,54,00,43,00,2c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,\
  66,00,74,00,20,00,4a,00,68,00,65,00,6e,00,67,00,48,00,65,00,69,00,20,00,55,\
  00,49,00,20,00,42,00,6f,00,6c,00,64,00,00,00,4d,00,53,00,59,00,48,00,42,00,\
  44,00,2e,00,54,00,54,00,43,00,2c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,\
  00,66,00,74,00,20,00,59,00,61,00,48,00,65,00,69,00,20,00,55,00,49,00,20,00,\
  42,00,6f,00,6c,00,64,00,2c,00,31,00,32,00,38,00,2c,00,39,00,36,00,00,00,4d,\
  00,53,00,59,00,48,00,42,00,44,00,2e,00,54,00,54,00,43,00,2c,00,4d,00,69,00,\
  63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,59,00,61,00,48,00,65,00,69,\
  00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,00,00,4d,00,41,00,4c,00,\
  47,00,55,00,4e,00,42,00,44,00,2e,00,54,00,54,00,46,00,2c,00,4d,00,61,00,6c,\
  00,67,00,75,00,6e,00,20,00,47,00,6f,00,74,00,68,00,69,00,63,00,20,00,42,00,\
  6f,00,6c,00,64,00,2c,00,31,00,31,00,38,00,2c,00,39,00,36,00,00,00,4d,00,41,\
  00,4c,00,47,00,55,00,4e,00,42,00,44,00,2e,00,54,00,54,00,46,00,2c,00,4d,00,\
  61,00,6c,00,67,00,75,00,6e,00,20,00,47,00,6f,00,74,00,68,00,69,00,63,00,20,\
  00,42,00,6f,00,6c,00,64,00,00,00,59,00,55,00,47,00,4f,00,54,00,48,00,42,00,\
  2e,00,54,00,54,00,43,00,2c,00,59,00,75,00,20,00,47,00,6f,00,74,00,68,00,69,\
  00,63,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,2c,00,31,00,32,00,\
  38,00,2c,00,39,00,36,00,00,00,59,00,55,00,47,00,4f,00,54,00,48,00,42,00,2e,\
  00,54,00,54,00,43,00,2c,00,59,00,75,00,20,00,47,00,6f,00,74,00,68,00,69,00,\
  63,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,00,00,53,00,45,00,47,\
  00,55,00,49,00,53,00,59,00,4d,00,2e,00,54,00,54,00,46,00,2c,00,53,00,65,00,\
  67,00,6f,00,65,00,20,00,55,00,49,00,20,00,53,00,79,00,6d,00,62,00,6f,00,6c,\
  00,00,00,00,00
"Ugh"=hex(2):27,00,54,00,65,00,73,00,74,00,69,00,6e,00,67,00,20,00,55,00,6e,00,\
  69,00,63,00,6f,00,64,00,65,00,20,00,63,00,68,00,61,00,72,00,73,00,20,00,59,\
  01,20,00,7e,01,20,00,0d,01,20,00,eb,30,59,30,57,30,4b,30,4d,30,27,00,29,00,\
  2e,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,00,00
" č ルすしか"=hex(2):27,00,54,00,65,00,73,00,74,00,69,00,6e,00,67,00,20,00,55,00,\
  6e,00,69,00,63,00,6f,00,64,00,65,00,20,00,63,00,68,00,61,00,72,00,73,00,20,\
  00,59,01,20,00,7e,01,20,00,0d,01,20,00,eb,30,59,30,57,30,4b,30,4d,30,27,00,\
  29,00,2e,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,00,\
  00

[HKEY_CURRENT_USER\Software\%1\ ルすしか\256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end]
"testing"=" ルすしか"
"か"=dword:00000002
"256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end"="Longer_than_256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|endsdfsdfasdfasdfasdfjlkasdjflkasjdflkjasdlfjaslkdfjlkasdjflkasdflksadlkjsadlfalsdfůlasdjflkasdjflkasjdflkůjasdflůkjasdlůfjalsůkdjflůksd"

[HKEY_CURRENT_USER\Software\%1\ ルすしか\256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end\256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end]

[HKEY_CURRENT_USER\Software\%1\ ルすしか\256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end\256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end\unreachable]

[HKEY_CURRENT_USER\Software\%1\ ルすしか\256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end\reachable]

[HKEY_CURRENT_USER\Software\%1\ ルすしか_testing_delete]

[HKEY_CURRENT_USER\Software\%1\ ルすしか_testing_delete\ughu]
"bledesu"="''Testing Unicode chars ř ž č ルすしかき'').          "
"しかき    "="Testus gradus"
" ř ž č ル.          "="Testing Unicode chars ř ž č ルすしかき"
"zero"=hex:
"non-zero"=hex:11,10
"す    "=hex:10
"dword_value"=dword:000023af
"き"=dword:234234af
"qwordvalue"=hex(b):ad,61,28,a3,95,0e,74,79
"qword_max"=hex(b):ff,ff,ff,ff,ff,ff,ff,ff
"すし"=hex(b):ef,ad,00,00,00,00,00,00
"Font_Leelawadee UI Bold"=hex(7):53,00,45,00,47,00,4f,00,45,00,55,00,49,00,42,\
  00,2e,00,54,00,54,00,46,00,2c,00,53,00,65,00,67,00,6f,00,65,00,20,00,55,00,\
  49,00,20,00,42,00,6f,00,6c,00,64,00,2c,00,31,00,31,00,30,00,2c,00,38,00,32,\
  00,00,00,53,00,45,00,47,00,4f,00,45,00,55,00,49,00,42,00,2e,00,54,00,54,00,\
  46,00,2c,00,53,00,65,00,67,00,6f,00,65,00,20,00,55,00,49,00,20,00,42,00,6f,\
  00,6c,00,64,00,00,00,4d,00,45,00,49,00,52,00,59,00,4f,00,42,00,2e,00,54,00,\
  54,00,43,00,2c,00,4d,00,65,00,69,00,72,00,79,00,6f,00,20,00,55,00,49,00,20,\
  00,42,00,6f,00,6c,00,64,00,2c,00,31,00,32,00,30,00,2c,00,39,00,36,00,00,00,\
  4d,00,45,00,49,00,52,00,59,00,4f,00,42,00,2e,00,54,00,54,00,43,00,2c,00,4d,\
  00,65,00,69,00,72,00,79,00,6f,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,\
  64,00,00,00,4d,00,53,00,4a,00,48,00,42,00,44,00,2e,00,54,00,54,00,43,00,2c,\
  00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,4a,00,68,00,\
  65,00,6e,00,67,00,48,00,65,00,69,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,\
  00,64,00,2c,00,31,00,32,00,30,00,2c,00,39,00,36,00,00,00,4d,00,53,00,4a,00,\
  48,00,42,00,44,00,2e,00,54,00,54,00,43,00,2c,00,4d,00,69,00,63,00,72,00,6f,\
  00,73,00,6f,00,66,00,74,00,20,00,4a,00,68,00,65,00,6e,00,67,00,48,00,65,00,\
  69,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,00,00,4d,00,53,00,59,\
  00,48,00,42,00,44,00,2e,00,54,00,54,00,43,00,2c,00,4d,00,69,00,63,00,72,00,\
  6f,00,73,00,6f,00,66,00,74,00,20,00,59,00,61,00,48,00,65,00,69,00,20,00,55,\
  00,49,00,20,00,42,00,6f,00,6c,00,64,00,2c,00,31,00,32,00,38,00,2c,00,39,00,\
  36,00,00,00,4d,00,53,00,59,00,48,00,42,00,44,00,2e,00,54,00,54,00,43,00,2c,\
  00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,59,00,61,00,\
  48,00,65,00,69,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,00,00,4d,\
  00,41,00,4c,00,47,00,55,00,4e,00,42,00,44,00,2e,00,54,00,54,00,46,00,2c,00,\
  4d,00,61,00,6c,00,67,00,75,00,6e,00,20,00,47,00,6f,00,74,00,68,00,69,00,63,\
  00,20,00,42,00,6f,00,6c,00,64,00,2c,00,31,00,31,00,38,00,2c,00,39,00,36,00,\
  00,00,4d,00,41,00,4c,00,47,00,55,00,4e,00,42,00,44,00,2e,00,54,00,54,00,46,\
  00,2c,00,4d,00,61,00,6c,00,67,00,75,00,6e,00,20,00,47,00,6f,00,74,00,68,00,\
  69,00,63,00,20,00,42,00,6f,00,6c,00,64,00,00,00,59,00,55,00,47,00,4f,00,54,\
  00,48,00,42,00,2e,00,54,00,54,00,43,00,2c,00,59,00,75,00,20,00,47,00,6f,00,\
  74,00,68,00,69,00,63,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,2c,\
  00,31,00,32,00,38,00,2c,00,39,00,36,00,00,00,59,00,55,00,47,00,4f,00,54,00,\
  48,00,42,00,2e,00,54,00,54,00,43,00,2c,00,59,00,75,00,20,00,47,00,6f,00,74,\
  00,68,00,69,00,63,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,00,00,\
  53,00,45,00,47,00,55,00,49,00,53,00,59,00,4d,00,2e,00,54,00,54,00,46,00,2c,\
  00,53,00,65,00,67,00,6f,00,65,00,20,00,55,00,49,00,20,00,53,00,79,00,6d,00,\
  62,00,6f,00,6c,00,00,00,00,00
"ř ž č ルすしか"=hex(7):27,00,54,00,65,00,73,00,74,00,69,00,6e,00,67,00,20,00,55,\
  00,6e,00,69,00,63,00,6f,00,64,00,65,00,20,00,63,00,68,00,61,00,72,00,73,00,\
  20,00,59,01,20,00,7e,01,20,00,0d,01,20,00,eb,30,59,30,57,30,4b,30,4d,30,27,\
  00,29,00,00,00,53,00,45,00,47,00,4f,00,45,00,55,00,49,00,42,00,2e,00,54,00,\
  54,00,46,00,2c,00,53,00,65,00,67,00,6f,00,65,00,20,00,55,00,49,00,20,00,42,\
  00,6f,00,6c,00,64,00,2c,00,31,00,31,00,30,00,2c,00,38,00,32,00,00,00,53,00,\
  45,00,47,00,4f,00,45,00,55,00,49,00,42,00,2e,00,54,00,54,00,46,00,2c,00,53,\
  00,65,00,67,00,6f,00,65,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,\
  00,00,4d,00,45,00,49,00,52,00,59,00,4f,00,42,00,2e,00,54,00,54,00,43,00,2c,\
  00,4d,00,65,00,69,00,72,00,79,00,6f,00,20,00,55,00,49,00,20,00,42,00,6f,00,\
  6c,00,64,00,2c,00,31,00,32,00,30,00,2c,00,39,00,36,00,00,00,4d,00,45,00,49,\
  00,52,00,59,00,4f,00,42,00,2e,00,54,00,54,00,43,00,2c,00,4d,00,65,00,69,00,\
  72,00,79,00,6f,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,00,00,4d,\
  00,53,00,4a,00,48,00,42,00,44,00,2e,00,54,00,54,00,43,00,2c,00,4d,00,69,00,\
  63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,4a,00,68,00,65,00,6e,00,67,\
  00,48,00,65,00,69,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,2c,00,\
  31,00,32,00,30,00,2c,00,39,00,36,00,00,00,4d,00,53,00,4a,00,48,00,42,00,44,\
  00,2e,00,54,00,54,00,43,00,2c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,\
  66,00,74,00,20,00,4a,00,68,00,65,00,6e,00,67,00,48,00,65,00,69,00,20,00,55,\
  00,49,00,20,00,42,00,6f,00,6c,00,64,00,00,00,4d,00,53,00,59,00,48,00,42,00,\
  44,00,2e,00,54,00,54,00,43,00,2c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,\
  00,66,00,74,00,20,00,59,00,61,00,48,00,65,00,69,00,20,00,55,00,49,00,20,00,\
  42,00,6f,00,6c,00,64,00,2c,00,31,00,32,00,38,00,2c,00,39,00,36,00,00,00,4d,\
  00,53,00,59,00,48,00,42,00,44,00,2e,00,54,00,54,00,43,00,2c,00,4d,00,69,00,\
  63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,59,00,61,00,48,00,65,00,69,\
  00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,00,00,4d,00,41,00,4c,00,\
  47,00,55,00,4e,00,42,00,44,00,2e,00,54,00,54,00,46,00,2c,00,4d,00,61,00,6c,\
  00,67,00,75,00,6e,00,20,00,47,00,6f,00,74,00,68,00,69,00,63,00,20,00,42,00,\
  6f,00,6c,00,64,00,2c,00,31,00,31,00,38,00,2c,00,39,00,36,00,00,00,4d,00,41,\
  00,4c,00,47,00,55,00,4e,00,42,00,44,00,2e,00,54,00,54,00,46,00,2c,00,4d,00,\
  61,00,6c,00,67,00,75,00,6e,00,20,00,47,00,6f,00,74,00,68,00,69,00,63,00,20,\
  00,42,00,6f,00,6c,00,64,00,00,00,59,00,55,00,47,00,4f,00,54,00,48,00,42,00,\
  2e,00,54,00,54,00,43,00,2c,00,59,00,75,00,20,00,47,00,6f,00,74,00,68,00,69,\
  00,63,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,2c,00,31,00,32,00,\
  38,00,2c,00,39,00,36,00,00,00,59,00,55,00,47,00,4f,00,54,00,48,00,42,00,2e,\
  00,54,00,54,00,43,00,2c,00,59,00,75,00,20,00,47,00,6f,00,74,00,68,00,69,00,\
  63,00,20,00,55,00,49,00,20,00,42,00,6f,00,6c,00,64,00,00,00,53,00,45,00,47,\
  00,55,00,49,00,53,00,59,00,4d,00,2e,00,54,00,54,00,46,00,2c,00,53,00,65,00,\
  67,00,6f,00,65,00,20,00,55,00,49,00,20,00,53,00,79,00,6d,00,62,00,6f,00,6c,\
  00,00,00,00,00
"Ugh"=hex(2):27,00,54,00,65,00,73,00,74,00,69,00,6e,00,67,00,20,00,55,00,6e,00,\
  69,00,63,00,6f,00,64,00,65,00,20,00,63,00,68,00,61,00,72,00,73,00,20,00,59,\
  01,20,00,7e,01,20,00,0d,01,20,00,eb,30,59,30,57,30,4b,30,4d,30,27,00,29,00,\
  2e,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,00,00
" č ルすしか"=hex(2):27,00,54,00,65,00,73,00,74,00,69,00,6e,00,67,00,20,00,55,00,\
  6e,00,69,00,63,00,6f,00,64,00,65,00,20,00,63,00,68,00,61,00,72,00,73,00,20,\
  00,59,01,20,00,7e,01,20,00,0d,01,20,00,eb,30,59,30,57,30,4b,30,4d,30,27,00,\
  29,00,2e,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,20,00,00,\
  00
[HKEY_CURRENT_USER\Software\%1\ ルすしか_testing_delete\zubr]

[HKEY_CURRENT_USER\Software\%1\ ルすしか_testing_delete\reg-none]
@=hex(0):

[HKEY_CURRENT_USER\Software\%1\ ルすしか_testing_delete\bobr]

[HKEY_CURRENT_USER\Software\%1\ ルすしか_testing_delete\bobr\boříččátka]
'

    "Created: / 16-11-2018 / 11:24:57 / svestkap"
    "Modified: / 16-06-2020 / 12:08:27 / svestkap"
! !

!Win32OperatingSystemTest methodsFor:'release'!

setUp
    | registryToImport randomString file returnString |

    self skipIf: OperatingSystem isMSWINDOWSlike not description: 'Windows only tests (registry manipulation)'.
    super setUp.
    
    windowsDetailsRegistryPath := 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion'.
    registryToImport := self unicodeRegistryExample.
    "/ Random is not always truly random so we add random process pid
    randomString := OperatingSystem getProcessId asString, '_', Random nextInteger asString.     
    "/ each test needs a random registry path
    registryToImport := registryToImport copy bindWith: 'SmalltalkX-tests_', randomString.
    
    "/ registry path which will be used  
    registryPath := registryToImport 
        copyFrom: (registryToImport indexOf: $[) + 1
        to: (registryToImport indexOf: $]) - 1.       
        
    "/ temporary file which will be used for importing
    file := Filename newTemporary.

    "/ Registry export is in UTF-16LE with BOM

    " What is BOM?
      A byte order mark (BOM) consists of the character code U+FEFF at the beginning of a data stream, where it can be used as a signature 
      defining the byte order and encoding form, primarily of unmarked plaintext files. Under some higher level protocols, use of a BOM may
      be mandatory (or prohibited) in the Unicode data stream defined in that protocol."

    "/ needed to write to file as Windows Registry do UTF16-LE With Signature
    " BOM for UTF-16is:
       FE FF    UTF-16, big-endian (BE)
       FF FE    UTF-16, little-endian (LE)"
    
    "/ Writing BOM first
    file writingFileDo: [ :stream |         
       stream nextPutUtf16: (Character codePoint:16rFFFE)         
    ].    
    
    "/ this is UTF16-LE (Little Endian) Without Signature (BOM)
    file appendingFileDo: [ :stream | stream nextPutAllUtf16Bytes: registryToImport MSB: false ].
     
    [   "/ adding registry entry so we can test it
        returnString := OperatingSystem getCommandOutputFrom: ('REG IMPORT ' , file asString)
    ] ensure: [ file remove ].
    
    "/ should REG IMPORT command fail the returnString is nil
    self deny: returnString isNil.
    "/ Check if testing registry entry was correctly created
    self deny: (OperatingSystem registryEntry key: registryPath) isNil.

    "Created: / 28-12-2016 / 22:12:14 / jv"
    "Modified (comment): / 16-06-2020 / 16:18:38 / svestkap"
!

tearDown
    self skipIf: OperatingSystem isMSWINDOWSlike not description: 'Windows specific tests'.
    super tearDown.
    
    "/ remove the added registry entry
    OperatingSystem getCommandOutputFrom:('REG DELETE "', registryPath, '" /f').

    "/ Check if testing registry was correctly deleted
    self assert: ((OperatingSystem registryEntry key: registryPath) isNil).

    "Created: / 16-11-2018 / 11:29:12 / svestkap"
! !

!Win32OperatingSystemTest methodsFor:'test-creatingProcess'!

testCorrectExec
    "Testing correctly executed cmd with arguments as string"
    | createProcessArgumentsLimit cmdInterpreterPath commandLineArguments atDir handle |
    
    "CreateProcess supports 32767 characters/bytes including all variables and values
     so take a good average for its arguments 4096"
    createProcessArgumentsLimit:= 4096.
    
    cmdInterpreterPath := OperatingSystem pathOfCommand: 'cmd'.
    self assert: cmdInterpreterPath size < createProcessArgumentsLimit. "/
    
    "/ cmd.exe - /C Carries out the command specified by string and then terminates
    commandLineArguments := '/C cd'.      
    self assert: commandLineArguments size = 5.
    
    atDir := Filename currentDirectory pathName.
    self assert: atDir size < createProcessArgumentsLimit.
    
    self shouldnt: [
         handle := OperatingSystem exec: cmdInterpreterPath withArguments: commandLineArguments
                     environment:nil
                 fileDescriptors:nil
                            fork:true
                         newPgrp:false
                     inDirectory: atDir.
    ] raise: Exception.
    
    self assert: handle notNil.
    self assert: (handle isKindOf: Win32OperatingSystem::Win32ProcessHandle).
    self assert: (OperatingSystem isProcessIdPresent: handle pid)

    "Created: / 21-10-2021 / 12:24:18 / svestkap"
!

testCorrectExec2
    "Testing correctly executed cmd with arguments as array"
    | createProcessArgumentsLimit cmdInterpreterPath commandLineArguments atDir handle |
    
    "CreateProcess supports 32767 characters/bytes including all variables and values
     so take a good average for its arguments 4096"
    createProcessArgumentsLimit:= 4096.          
    
    cmdInterpreterPath := OperatingSystem pathOfCommand: 'cmd'.
    self assert: cmdInterpreterPath size < createProcessArgumentsLimit.
    
    commandLineArguments := Array new: 2.
    commandLineArguments at: 1 put: '/C'. "/Carries out the command specified by string and then terminates
    commandLineArguments at: 2 put: 'cd'.
    self assert: commandLineArguments size = 2.
    
    atDir := Filename currentDirectory pathName.
    self assert: atDir size < createProcessArgumentsLimit.      
    
    self shouldnt: [
         handle := OperatingSystem exec: cmdInterpreterPath withArguments: commandLineArguments
                     environment:nil
                 fileDescriptors:nil
                            fork:true
                         newPgrp:false
                     inDirectory: Filename currentDirectory pathName.
    ] raise: Exception.
    
    self assert: handle notNil.
    self assert: (handle isKindOf: Win32OperatingSystem::Win32ProcessHandle).
    self assert: (OperatingSystem isProcessIdPresent: handle pid)

    "Created: / 21-10-2021 / 12:24:31 / svestkap"
!

testExecCreatedProcessError
    "Testing created process exception is proceedable"
    | commandLine savedException |
      
    commandLine := '..'.
    self assert: commandLine size = 2.
        
    self should: [
         OperatingSystem exec: 'cd' withArguments: commandLine
                  environment:nil
              fileDescriptors:nil
                         fork:true
                      newPgrp:false
                  inDirectory: Filename currentDirectory pathName
    ] raise: OsError
    suchThat: [ :ex | 
        savedException := ex.
        ex errorSymbol == #'ERROR_FILE_NOT_FOUND'
    ].

    "Created: / 21-10-2021 / 12:16:45 / svestkap"
    "Modified: / 25-08-2022 / 11:21:04 / jv"
!

testExecCreatedProcessError2
    "Testing if created process exception proceeds with nil"
    | commandLine handle |
      
    commandLine := '..'.
    self assert: commandLine size = 2.
    
    handle := Win32OperatingSystem::Win32ProcessHandle new.
    self assert: handle notNil.
    self assert: (handle isKindOf: Win32OperatingSystem::Win32ProcessHandle).
    self assert: handle pid isNil.       
    
    Exception handle: [ :ex |
        ex proceed
    ] do: [ 
        handle := OperatingSystem exec: 'cd' withArguments: commandLine
                           environment:nil
                       fileDescriptors:nil
                                  fork:true
                               newPgrp:false
                           inDirectory: Filename currentDirectory pathName
    ].
    "/ after exception has occured, continue to see if handle is nil    
    self assert: handle isNil.

    "Created: / 21-10-2021 / 12:54:07 / svestkap"
!

testExecWithTooLongCommandLine
    "Creating process with too long command line - should raise an exception"
    | beyondCreateProcessArgumentsLimit commandLine savedException |
    
    beyondCreateProcessArgumentsLimit := 4096.    
    commandLine := RandomGenerator new nextLettersOrDigits: beyondCreateProcessArgumentsLimit.
    self assert: commandLine size = beyondCreateProcessArgumentsLimit.
    
    self should: [
        OperatingSystem exec: '' withArguments: commandLine
                 environment:nil
             fileDescriptors:nil
                        fork:true
                     newPgrp:false
                 inDirectory: Filename currentDirectory pathName
    ] raise: Exception
    suchThat: [ :ex | 
        savedException := ex.
        ex errorSymbol == #'ERROR_INVALID_PARAMETER'
    ].

    "Created: / 21-10-2021 / 12:16:53 / svestkap"
    "Modified: / 25-08-2022 / 11:22:06 / jv"
!

testExecWithTooLongCommandLine2
    "Testing if the exception is proceedable and if it returns nil"
    | beyondCreateProcessArgumentsLimit commandLine handle |
    
    beyondCreateProcessArgumentsLimit := 4097.         
    "/ created random String size 4097
    commandLine := RandomGenerator new nextLettersOrDigits: beyondCreateProcessArgumentsLimit.
    self assert: commandLine size = beyondCreateProcessArgumentsLimit.
    
    handle := Win32OperatingSystem::Win32ProcessHandle new.
    self assert: handle notNil.
    self assert: (handle isKindOf: Win32OperatingSystem::Win32ProcessHandle).
    self assert: handle pid isNil.
    
    Exception handle: [ :ex | 
        ex proceed
    ] do: [ 
         handle := OperatingSystem exec: '' withArguments: commandLine
                     environment:nil
                 fileDescriptors:nil
                            fork:true
                         newPgrp:false
                     inDirectory: Filename currentDirectory pathName
    ]. 
    "/ after exception has occured, continue to see if handle is nil    
    self assert: handle isNil.

    "Created: / 21-10-2021 / 12:17:02 / svestkap"
    "Modified: / 20-05-2022 / 13:58:16 / Patrik Svestka <patrik.svestka@gmail.com>"
!

testExecWithTooLongCommandPath
    "Creating process with too long command path - should raise an exception"
    | beyondCreateProcessArgumentsLimit commandPath savedException |
    
    beyondCreateProcessArgumentsLimit := 4096.
    commandPath := RandomGenerator new nextLettersOrDigits: beyondCreateProcessArgumentsLimit.
    self assert: commandPath size = beyondCreateProcessArgumentsLimit.
    
    self should: [
        OperatingSystem exec: commandPath withArguments: ''
                 environment:nil
             fileDescriptors:nil
                        fork:true
                     newPgrp:false
                 inDirectory: Filename currentDirectory pathName
    ] raise: Exception
    suchThat: [ :ex | 
        savedException := ex.
        ex errorSymbol == #'ERROR_INVALID_PARAMETER'
    ].

    "Created: / 21-10-2021 / 12:18:26 / svestkap"
    "Modified: / 25-08-2022 / 11:22:56 / jv"
!

testExecWithTooLongCommandPath2
    "Testing if the exception is proceedable and if it returns nil"
    | beyondCreateProcessArgumentsLimit commandPath handle |
    
    beyondCreateProcessArgumentsLimit := 4097.
    "/ created random String size 4097
    commandPath := RandomGenerator new nextLettersOrDigits: beyondCreateProcessArgumentsLimit.
    self assert: commandPath size = beyondCreateProcessArgumentsLimit.
    
    handle := Win32OperatingSystem::Win32ProcessHandle new.
    self assert: handle notNil.
    self assert: (handle isKindOf: Win32OperatingSystem::Win32ProcessHandle).
    self assert: handle pid isNil.
    
    Exception handle: [ :ex | 
        ex proceed
    ] do: [ 
         handle := OperatingSystem exec: commandPath withArguments: ''
                     environment:nil
                 fileDescriptors:nil
                            fork:true
                         newPgrp:false
                     inDirectory: Filename currentDirectory pathName
    ]. 
    "/ after exception has occured, continue to see if handle is nil    
    self assert: handle isNil.

    "Created: / 21-10-2021 / 12:19:37 / svestkap"
    "Modified: / 20-05-2022 / 13:58:03 / Patrik Svestka <patrik.svestka@gmail.com>"
!

testExecWithTooLongDirName
    "Creating process with too long command path - should raise an exception"
    | beyondCreateProcessArgumentsLimit dirName savedException |
    
    beyondCreateProcessArgumentsLimit := 4096.
    dirName := RandomGenerator new nextLettersOrDigits: beyondCreateProcessArgumentsLimit.
    self assert: dirName size = beyondCreateProcessArgumentsLimit.
    
    self should: [
        OperatingSystem exec: '' withArguments: ''
                 environment:nil
             fileDescriptors:nil
                        fork:true
                     newPgrp:false
                 inDirectory: dirName
    ] raise: Exception
    suchThat: [ :ex | 
        savedException := ex.
        ex errorSymbol == #'ERROR_INVALID_PARAMETER'
    ].

    "Created: / 21-10-2021 / 12:22:38 / svestkap"
    "Modified: / 25-08-2022 / 11:23:15 / jv"
!

testExecWithTooLongDirName2
    "Testing if the exception is proceedable and if it returns nil"
    | beyondCreateProcessArgumentsLimit dirName handle |
    
    beyondCreateProcessArgumentsLimit := 4097.
    dirName := RandomGenerator new nextLettersOrDigits: beyondCreateProcessArgumentsLimit.
    self assert: dirName size = beyondCreateProcessArgumentsLimit.
    
    handle := Win32OperatingSystem::Win32ProcessHandle new.
    self assert: handle notNil.
    self assert: (handle isKindOf: Win32OperatingSystem::Win32ProcessHandle).
    self assert: handle pid isNil.
    
    Exception handle: [ :ex | 
        ex proceed
    ] do: [ 
         handle := OperatingSystem exec: '' withArguments: ''
                     environment:nil
                 fileDescriptors:nil
                            fork:true
                         newPgrp:false
                     inDirectory: dirName
    ]. 
    "/ after exception has occured, continue to see if handle is nil    
    self assert: handle isNil.

    "Created: / 21-10-2021 / 12:21:54 / svestkap"
    "Modified: / 20-05-2022 / 13:35:31 / Patrik Svestka <patrik.svestka@gmail.com>"
! !

!Win32OperatingSystemTest methodsFor:'tests'!

testMutex
    |handle alreadyExists lastErrorCode handleAndLastErrorCode|

    handleAndLastErrorCode := Win32OperatingSystem createMutexNamed: UUID new printString.
    handle := handleAndLastErrorCode first.
    handle isNil ifTrue:[^ self].
    lastErrorCode := handleAndLastErrorCode second.
    self assert: lastErrorCode == 0.
    alreadyExists := (lastErrorCode == 5 "ERROR_ACCESS_DENIED" or:[ lastErrorCode == 183 "ERROR_ALREADY_EXISTS"]).
    alreadyExists ifTrue:[
        Transcript showCR: 'Mutex already exists!!'.
        ^ self.
    ].
    [
        Transcript showCR: 'Mutex created!!'.
        Win32OperatingSystem waitForSingleObject: handle.
        Delay waitForSeconds:0.5. "/ self halt.
        Win32OperatingSystem releaseMutex: handle.
    ] ensure:[
        Win32OperatingSystem primCloseHandle: handle.
        Transcript showCR: 'Mutex closed!!'.
    ].


    "
     self new testMutex
    "

    "Modified: / 28-06-2018 / 09:14:35 / jv"
!

testRegistry
    |k hasContentType|

    k := OperatingSystem registryEntry key:'HKEY_CLASSES_ROOT\MIME\Database\'.
    self assert:(k notNil).

    hasContentType := false.
    k subKeyNamesAndClassesDo:[:nm :clsNm |
        "/ Transcript showCR:nm.
        nm = 'Content Type' ifTrue:[hasContentType := true].
    ].
    self assert:hasContentType.

    "/ k subKeysDo:[:k | Transcript showCR:k].

    "
     self new testRegistry
    "

    "Modified: / 28-12-2016 / 22:13:43 / jv"
!

testRegistry02a
    | root key |

    root :=OperatingSystem registryEntry key:'HKEY_CURRENT_USER'.
    root deleteSubKeyNamed: testSelector.

    self assert:(root subKeyNamed: testSelector) isNil.
    self deny: (root deleteSubKeyNamed: testSelector).

    key := root createSubKeyNamed:testSelector.
    self assert: key notNil.
    self assert:(root subKeyNamed: testSelector) notNil.

    self assert: (root deleteSubKeyNamed:testSelector).
    self assert:(root subKeyNamed: testSelector) isNil.
    self deny: (root deleteSubKeyNamed: testSelector).

    "Created: / 28-12-2016 / 23:14:15 / jv"
    "Modified: / 05-01-2017 / 21:45:20 / jv"
! !

!Win32OperatingSystemTest methodsFor:'tests-UnicodeCreate'!

testCreatingSubKeyNamed_01
    "Testing if new subKey is created"
    | readData testingRegistryPath readSubKeys subKeysCount |   
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readSubKeys := testingRegistryPath subKeys. 
    subKeysCount := readSubKeys size.
    
    self assert: subKeysCount = 3.
    "/ creating the new subKey    
    readData := testingRegistryPath subKeyNamed: 'bledesu ル' flags: nil createIfAbsent: true.
    "/ check if new path is with the subKeyNamed above
    self assert: (readData path copyAfterLast: $\) = 'bledesu ル' .
    
    readSubKeys := testingRegistryPath subKeys.
    self assert: readSubKeys size = (subKeysCount + 1)
    
    "
     self run:#testCreatingSubKeyNamed_01
     self new testCreatingSubKeyNamed_01
    "

    "Created: / 07-12-2018 / 15:30:55 / svestkap"
    "Modified: / 12-02-2019 / 14:48:57 / svestkap"
!

testCreatingSubKeyNamed_02
    "Testing if new subKey is created via createSubKeyNamed:"
    | readData testingRegistryPath readSubKeys subKeysCount |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readSubKeys := testingRegistryPath subKeys. 
    subKeysCount := readSubKeys size.

    self assert: subKeysCount = 3.
    "/ creating the new subKey    
    readData := testingRegistryPath createSubKeyNamed: 'bledesu ル'.
    "/ check if new path is with the subKeyNamed above
    self assert: (readData path copyAfterLast: $\) = 'bledesu ル' .

    readSubKeys := testingRegistryPath subKeys.
    self assert: readSubKeys size = (subKeysCount + 1)

    "
     self run:#testCreatingSubKeyNamed_02
     self new testCreatingSubKeyNamed_02
    "

    "Created: / 07-12-2018 / 15:57:09 / svestkap"
    "Modified: / 12-02-2019 / 14:48:53 / svestkap"
!

testCreatingSubKeyNamed_Wow64_32_01
    "Testing if new subKey is created in Wow64_32 (32bit program reading 32bit registry)"
    | windowsVersion readData testingRegistryPath readSubKeys subKeysCount |

    windowsVersion := Win32OperatingSystem registryEntry key: windowsDetailsRegistryPath.
    self skipIf: (windowsVersion valueNamed: 'BuildLabEx') isNil description: 'Skipping test the registry key does not exist.  Happens in some ancient Windows (XP)'.
    self skipIf: ((windowsVersion valueNamed: 'BuildLabEx') includesString: 'x86')  description: 'Skip test if on 32bit Windows (x86)'.  "/ amd64 for x64 Windows
        
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readSubKeys := testingRegistryPath subKeys. 
    subKeysCount := readSubKeys size.
    
    self assert: subKeysCount = 3.
    "/ creating the new subKey    
    readData := testingRegistryPath subKeyNamed: 'bledesu ル' flags: #KEY_WOW64_32KEY createIfAbsent: true.
    "/ check if new path is with the subKeyNamed above
    self assert: (readData path copyAfterLast: $\) = 'bledesu ル' .
    
    readSubKeys := testingRegistryPath subKeys.
    self assert: readSubKeys size = (subKeysCount + 1)

    "
     self run:#testCreatingSubKeyNamed_Wow64_32_01
     self new testCreatingSubKeyNamed_Wow64_32_01
    "

    "Created: / 07-12-2018 / 15:58:24 / svestkap"
    "Modified: / 12-02-2019 / 14:47:40 / svestkap"
!

testCreatingSubKeyNamed_Wow64_32_02
    "Testing if new subKey is created in Wow64_32 (32bit program reading 32bit registry) via createSubKeyNamed:flags:"
    | windowsVersion readData testingRegistryPath readSubKeys subKeysCount |

    windowsVersion := Win32OperatingSystem registryEntry key: windowsDetailsRegistryPath.
    self skipIf: (windowsVersion valueNamed: 'BuildLabEx') isNil description: 'Skipping test the registry key does not exist.  Happens in some ancient Windows (XP)'.
    self skipIf: ((windowsVersion valueNamed: 'BuildLabEx') includesString: 'x86')  description: 'Skip test if on 32bit Windows (x86)'.  "/ amd64 for x64 Windows
                                                                   
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readSubKeys := testingRegistryPath subKeys. 
    subKeysCount := readSubKeys size.

    self assert: subKeysCount = 3.
    "/ creating the new subKey    
    readData := testingRegistryPath createSubKeyNamed: 'bledesu ル' flags: #KEY_WOW64_32KEY.
    "/ check if new path is with the subKeyNamed above
    self assert: (readData path copyAfterLast: $\) = 'bledesu ル' .

    readSubKeys := testingRegistryPath subKeys.
    self assert: readSubKeys size = (subKeysCount + 1)

    "
     self run:#testCreatingSubKeyNamed_Wow64_32_02
     self new testCreatingSubKeyNamed_Wow64_32_02
    "

    "Created: / 07-12-2018 / 15:59:32 / svestkap"
    "Modified: / 12-02-2019 / 14:47:57 / svestkap"
!

testCreatingSubKeyNamed_Wow64_64_01
    "Testing if new subKey is created in Wow64_32 (32bit program reading 64bit registry)"
    | windowsVersion readData testingRegistryPath readSubKeys subKeysCount |

    windowsVersion := Win32OperatingSystem registryEntry key: windowsDetailsRegistryPath.
    self skipIf: (windowsVersion valueNamed: 'BuildLabEx') isNil description: 'Skipping test the registry key does not exist.  Happens in some ancient Windows (XP)'.
    self skipIf: ((windowsVersion valueNamed: 'BuildLabEx') includesString: 'x86')  description: 'Skip test if on 32bit Windows (x86)'.  "/ amd64 for x64 Windows
 
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readSubKeys := testingRegistryPath subKeys. 
    subKeysCount := readSubKeys size.
    
    self assert: subKeysCount = 3.
    "/ creating the new subKey    
    readData := testingRegistryPath subKeyNamed: 'bledesu ル' flags: #KEY_WOW64_64KEY createIfAbsent: true.
    "/ check if new path is with the subKeyNamed above
    self assert: (readData path copyAfterLast: $\) = 'bledesu ル' .
    
    readSubKeys := testingRegistryPath subKeys.
    self assert: readSubKeys size = (subKeysCount + 1)

    "
     self run:#testCreatingSubKeyNamed_Wow64_64_01
     self new testCreatingSubKeyNamed_Wow64_64_01
    "

    "Created: / 07-12-2018 / 15:58:38 / svestkap"
    "Modified: / 12-02-2019 / 14:48:17 / svestkap"
!

testCreatingSubKeyNamed_Wow64_64_02
    "Testing if new subKey is created in Wow64_32 (32bit program reading 64bit registry) via createSubKeyNamed:flags:"
    | windowsVersion readData testingRegistryPath readSubKeys subKeysCount |

    windowsVersion := Win32OperatingSystem registryEntry key: windowsDetailsRegistryPath.
    self skipIf: (windowsVersion valueNamed: 'BuildLabEx') isNil description: 'Skipping test the registry key does not exist.  Happens in some ancient Windows (XP)'.
    self skipIf: ((windowsVersion valueNamed: 'BuildLabEx') includesString: 'x86')  description: 'Skip test if on 32bit Windows (x86)'.  "/ amd64 for x64 Windows
 
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readSubKeys := testingRegistryPath subKeys. 
    subKeysCount := readSubKeys size.
    
    self assert: subKeysCount = 3.
    "/ creating the new subKey    
    readData := testingRegistryPath createSubKeyNamed: 'bledesu ル' flags: #KEY_WOW64_64KEY.
    "/ check if new path is with the subKeyNamed above
    self assert: (readData path copyAfterLast: $\) = 'bledesu ル' .
    
    readSubKeys := testingRegistryPath subKeys.
    self assert: readSubKeys size = (subKeysCount + 1)

    "
     self run:#testCreatingSubKeyNamed_Wow64_64_02
     self new testCreatingSubKeyNamed_Wow64_64_02
    "

    "Created: / 07-12-2018 / 15:59:50 / svestkap"
    "Modified: / 12-02-2019 / 14:48:41 / svestkap"
! !

!Win32OperatingSystemTest methodsFor:'tests-UnicodeOpen'!

testOpenSubKeyNamed_01
    "Testing if an old subKey is opened"
    | readData testingRegistryPath readSubKeys subKeysCount |
       
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readSubKeys := testingRegistryPath subKeys. 
    subKeysCount := readSubKeys size.
    
    self assert: subKeysCount = 3.
    "/ trying to read already existing subKey    
    readData := testingRegistryPath subKeyNamed: ' ルすしか' flags: nil createIfAbsent: false.

    "/ check if the existing
    self assert: (readData path copyAfterLast: $\) = ' ルすしか'.    
    
    "
     self run:#testOpenSubKeyNamed_01
     self new testOpenSubKeyNamed_01
    "

    "Created: / 07-12-2018 / 15:34:21 / svestkap"
    "Modified: / 12-02-2019 / 14:49:06 / svestkap"
!

testOpenSubKeyNamed_02
    "Testing if an old subKey is opened"
    | readData testingRegistryPath readSubKeys subKeysCount |
     
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readSubKeys := testingRegistryPath subKeys. 
    subKeysCount := readSubKeys size.
    
    self assert: subKeysCount = 3.
    "/ trying to read already existing subKey    
    readData := testingRegistryPath subKeyNamed: ' ルすしか' flags: nil createIfAbsent: true.

    "/ check if the existing
    self assert: (readData path copyAfterLast: $\) = ' ルすしか'.    
    
    "
     self run:#testOpenSubKeyNamed_02
     self new testOpenSubKeyNamed_02
    "

    "Created: / 07-12-2018 / 15:36:27 / svestkap"
    "Modified: / 12-02-2019 / 14:49:10 / svestkap"
!

testOpenSubKeyNamed_03
    "Testing if an old subKey is opened via subKeyNamed:"
    | readData testingRegistryPath readSubKeys subKeysCount |
     
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readSubKeys := testingRegistryPath subKeys. 
    subKeysCount := readSubKeys size.
    
    self assert: subKeysCount = 3.
    "/ trying to read already existing subKey    
    readData := testingRegistryPath subKeyNamed: ' ルすしか'.

    "/ check if the existing
    self assert: (readData path copyAfterLast: $\) = ' ルすしか'.    
    
    "
     self run:#testOpenSubKeyNamed_03
     self new testOpenSubKeyNamed_03
    "

    "Created: / 07-12-2018 / 15:47:59 / svestkap"
    "Modified: / 12-02-2019 / 14:49:15 / svestkap"
!

testOpenSubKeyNamed_04
    "Testing if an old subKey is opened via subKeyNamed:createIfAbsent:"
    | readData testingRegistryPath readSubKeys subKeysCount |
     
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readSubKeys := testingRegistryPath subKeys. 
    subKeysCount := readSubKeys size.
    
    self assert: subKeysCount = 3.
    "/ trying to read already existing subKey    
    readData := testingRegistryPath subKeyNamed: ' ルすしか' createIfAbsent: true.

    "/ check if the existing
    self assert: (readData path copyAfterLast: $\) = ' ルすしか'.    
    
    "
     self run:#testOpenSubKeyNamed_04
     self new testOpenSubKeyNamed_04
    "

    "Created: / 07-12-2018 / 15:51:52 / svestkap"
    "Modified: / 12-02-2019 / 14:49:20 / svestkap"
!

testOpenSubKeyNamed_05
    "Testing an error is raised when number is used to access the subKey via subKeyNamed:createIfAbsent:"
    | testingRegistryPath readSubKeys subKeysCount |
     
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readSubKeys := testingRegistryPath subKeys. 
    subKeysCount := readSubKeys size.
    
    self assert: subKeysCount = 3.
    "/ trying to read already existing subKey    
    self should: [ testingRegistryPath subKeyNamed: 11 createIfAbsent: true ] 
         raise: Error 
         suchThat: [ :e | e messageText = 'subKeyString is not a string!!' ]
         
    "
     self run:#testOpenSubKeyNamed_05
     self new testOpenSubKeyNamed_05
    "

    "Created: / 01-02-2019 / 15:58:49 / svestkap"
!

testOpenSubKeyNamed_Wow64_32_01 
    "Testing if an old subKey is opened in Wow64_32 (32bit program reading 32bit registry)"
    | windowsVersion readData testingRegistryPath readSubKeys subKeysCount |
   
    windowsVersion := Win32OperatingSystem registryEntry key: windowsDetailsRegistryPath.
    self skipIf: (windowsVersion valueNamed: 'BuildLabEx') isNil description: 'Skipping test the registry key does not exist.  Happens in some ancient Windows (XP)'.
    self skipIf: ((windowsVersion valueNamed: 'BuildLabEx') includesString: 'x86')  description: 'Skip test if on 32bit Windows (x86)'.  "/ amd64 for x64 Windows
        
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readSubKeys := testingRegistryPath subKeys. 
    subKeysCount := readSubKeys size.
    
    self assert: subKeysCount = 3.
    "/ trying to read already existing subKey    
    readData := testingRegistryPath subKeyNamed: ' ルすしか' flags: #KEY_WOW64_32KEY createIfAbsent: false.

    "/ check if the existing
    self assert: (readData path copyAfterLast: $\) = ' ルすしか'.    
    
    "
     self run:#testOpenSubKeyNamed_Wow64_32_01
     self new testOpenSubKeyNamed_Wow64_32_01
    "

    "Created: / 07-12-2018 / 15:53:04 / svestkap"
    "Modified: / 12-02-2019 / 14:47:03 / svestkap"
!

testOpenSubKeyNamed_Wow64_32_02
    "Testing if an old subKey is opened in Wow64_32 (32bit program reading 32bit registry) via subKeyNamed:flags:"
    | windowsVersion readData testingRegistryPath readSubKeys subKeysCount |
   
    windowsVersion := Win32OperatingSystem registryEntry key: windowsDetailsRegistryPath.
    self skipIf: (windowsVersion valueNamed: 'BuildLabEx') isNil description: 'Skipping test the registry key does not exist.  Happens in some ancient Windows (XP)'.
    self skipIf: ((windowsVersion valueNamed: 'BuildLabEx') includesString: 'x86')  description: 'Skip test if on 32bit Windows (x86)'.  "/ amd64 for x64 Windows
                                                                     
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readSubKeys := testingRegistryPath subKeys. 
    subKeysCount := readSubKeys size.
    
    self assert: subKeysCount = 3.
    "/ trying to read already existing subKey    
    readData := testingRegistryPath subKeyNamed: ' ルすしか' flags: #KEY_WOW64_32KEY.

    "/ check if the existing
    self assert: (readData path copyAfterLast: $\) = ' ルすしか'.    
    
    "
     self run:#testOpenSubKeyNamed_Wow64_32_02
     self new testOpenSubKeyNamed_Wow64_32_02
    "

    "Created: / 07-12-2018 / 15:54:31 / svestkap"
    "Modified: / 12-02-2019 / 14:47:06 / svestkap"
!

testOpenSubKeyNamed_Wow64_64_01
    "Testing if an old subKey is opened in Wow64_64 (32bit program reading 64bit registry)"
    | windowsVersion readData testingRegistryPath readSubKeys subKeysCount |

    windowsVersion := Win32OperatingSystem registryEntry key: windowsDetailsRegistryPath.
    self skipIf: (windowsVersion valueNamed: 'BuildLabEx') isNil description: 'Skipping test the registry key does not exist.  Happens in some ancient Windows (XP)'.
    self skipIf: ((windowsVersion valueNamed: 'BuildLabEx') includesString: 'x86')  description: 'Skip test if on 32bit Windows (x86)'.  "/ amd64 for x64 Windows
                                                                    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readSubKeys := testingRegistryPath subKeys. 
    subKeysCount := readSubKeys size.
    
    self assert: subKeysCount = 3.
    "/ trying to read already existing subKey    
    readData := testingRegistryPath subKeyNamed: ' ルすしか' flags: #KEY_WOW64_64KEY createIfAbsent: false.

    "/ check if the existing
    self assert: (readData path copyAfterLast: $\) = ' ルすしか'.    
    
    "
     self run:#testOpenSubKeyNamed_Wow64_64_01
     self new testOpenSubKeyNamed_Wow64_64_01
    "

    "Created: / 07-12-2018 / 15:53:34 / svestkap"
    "Modified: / 12-02-2019 / 14:47:09 / svestkap"
!

testOpenSubKeyNamed_Wow64_64_02
    "Testing if an old subKey is opened in Wow64_64 (32bit program reading 64bit registry) via subKeyNamed:flags:"
    | windowsVersion readData testingRegistryPath readSubKeys subKeysCount |
   
    windowsVersion := Win32OperatingSystem registryEntry key: windowsDetailsRegistryPath.
    self skipIf: (windowsVersion valueNamed: 'BuildLabEx') isNil description: 'Skipping test the registry key does not exist.  Happens in some ancient Windows (XP)'.
    self skipIf: ((windowsVersion valueNamed: 'BuildLabEx') includesString: 'x86')  description: 'Skip test if on 32bit Windows (x86)'.  "/ amd64 for x64 Windows
                                                                    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readSubKeys := testingRegistryPath subKeys. 
    subKeysCount := readSubKeys size.
    
    self assert: subKeysCount = 3.
    "/ trying to read already existing subKey    
    readData := testingRegistryPath subKeyNamed: ' ルすしか' flags: #KEY_WOW64_64KEY.

    "/ check if the existing
    self assert: (readData path copyAfterLast: $\) = ' ルすしか'.    
    
    "
     self run:#testOpenSubKeyNamed_Wow64_64_02
     self new testOpenSubKeyNamed_Wow64_64_02
    "

    "Created: / 07-12-2018 / 15:55:07 / svestkap"
    "Modified: / 12-02-2019 / 14:47:13 / svestkap"
!

testOpenSubKeyNamed_nonExistingWow64_32
    "Trying to read non-existing subKey in Wow64_32 (32bit program reading 32bit registry)"
    | windowsVersion readData testingRegistryPath readSubKeys subKeysCount |
   
    windowsVersion := Win32OperatingSystem registryEntry key: windowsDetailsRegistryPath.
    self skipIf: (windowsVersion valueNamed: 'BuildLabEx') isNil description: 'Skipping test the registry key does not exist.  Happens in some ancient Windows (XP)'.
    self skipIf: ((windowsVersion valueNamed: 'BuildLabEx') includesString: 'x86')  description: 'Skip test if on 32bit Windows (x86)'.  "/ amd64 for x64 Windows
                                                                       
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readSubKeys := testingRegistryPath subKeys. 
    subKeysCount := readSubKeys size.
    
    self assert: subKeysCount = 3.
    "/ trying to read non-existent subKey    
    readData := testingRegistryPath subKeyNamed: 'bledesu ル' flags: #KEY_WOW64_32KEY createIfAbsent: false.
    "/ check if new path is with the subKeyNamed above

    self assert: readData isNil
    
    "
     self run:#testOpenSubKeyNamed_nonExistingWow64_32
     self new testOpenSubKeyNamed_nonExistingWow64_32
    "

    "Created: / 07-12-2018 / 15:44:52 / svestkap"
    "Modified: / 12-02-2019 / 14:47:17 / svestkap"
!

testOpenSubKeyNamed_nonExistingWow64_64
    "Trying to read non-existing subKey in Wow64_32 (32bit program reading 64bit registry)"
    | windowsVersion readData testingRegistryPath readSubKeys subKeysCount |
   
    windowsVersion := Win32OperatingSystem registryEntry key: windowsDetailsRegistryPath.
    self skipIf: (windowsVersion valueNamed: 'BuildLabEx') isNil description: 'Skipping test the registry key does not exist.  Happens in some ancient Windows (XP)'.
    self skipIf: ((windowsVersion valueNamed: 'BuildLabEx') includesString: 'x86')  description: 'Skip test if on 32bit Windows (x86)'.  "/ amd64 for x64 Windows
                                                                   
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readSubKeys := testingRegistryPath subKeys. 
    subKeysCount := readSubKeys size.
    
    self assert: subKeysCount = 3.
    "/ trying to read non-existent subKey    
    readData := testingRegistryPath subKeyNamed: 'bledesu ル' flags: #KEY_WOW64_64KEY createIfAbsent: false.
    "/ check if new path is with the subKeyNamed above

    self assert: readData isNil
    
    "
     self run:#testOpenSubKeyNamed_nonExistingWow64_32
     self new testOpenSubKeyNamed_nonExistingWow64_32
    "

    "Created: / 07-12-2018 / 15:45:42 / svestkap"
    "Modified: / 12-02-2019 / 14:47:21 / svestkap"
!

testOpenSubKeyNamed_nonExisting_01
    "Trying to read non-existing subKey via subKeyNamed:flags:createIfAbsent:"
    | readData testingRegistryPath readSubKeys subKeysCount |
       
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readSubKeys := testingRegistryPath subKeys. 
    subKeysCount := readSubKeys size.    
    self assert: subKeysCount = 3.
    
    "/ trying to read non-existent subKey    
    readData := testingRegistryPath subKeyNamed: 'bledesu ル' flags: nil createIfAbsent: false.
    "/ check if new path is with the subKeyNamed above
    self assert: readData isNil
    
    "
     self run:#testOpenSubKeyNamed_nonExisting_01
     self new testOpenSubKeyNamed_nonExisting_01
    "

    "Created: / 07-12-2018 / 15:50:18 / svestkap"
    "Modified: / 12-02-2019 / 14:49:32 / svestkap"
!

testOpenSubKeyNamed_nonExisting_02
    "Trying to read non-existing subKey via subKeyNamed:"
    | readData testingRegistryPath readSubKeys subKeysCount |
   
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readSubKeys := testingRegistryPath subKeys. 
    subKeysCount := readSubKeys size.    
    self assert: subKeysCount = 3.
    
    "/ trying to read non-existent subKey    
    readData := testingRegistryPath subKeyNamed: 'bledesu ル'.
    "/ check if new path is with the subKeyNamed above
    self assert: readData isNil
    
    "
     self run:#testOpenSubKeyNamed_nonExisting_02
     self new testOpenSubKeyNamed_nonExisting_02
    "

    "Created: / 07-12-2018 / 15:50:48 / svestkap"
    "Modified: / 12-02-2019 / 14:49:36 / svestkap"
! !

!Win32OperatingSystemTest methodsFor:'tests-unicodeDelete'!

testDeleteSubKeyNamed_01
    "Testing deleting of empty subKey via deleteSubKeyNamed:"  
    | returnValue testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key:  registryPath.
    
    "/ if successfully deteted -> true 
    returnValue := testingRegistryPath deleteSubKeyNamed: ' ルすしか_empty'.
    self assert: returnValue
 
    "
     self run:#testDeleteSubKeyNamed_01
     self new testDeleteSubKeyNamed_01
    "

    "Created: / 30-01-2019 / 15:42:27 / svestkap"
    "Modified (format): / 01-02-2019 / 14:59:58 / svestkap"
!

testDeleteSubKeyNamed_02
    "Testing deleting of empty subKey via deleteSubKeyNamed:"
    | testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key:  registryPath.
    
    self should: [ testingRegistryPath deleteSubKeyNamed: 11 ] 
         raise: Error 
         suchThat: [ :e | e messageText = 'subKeyString is not a string!!' ].            
 
    "
     self run:#testDeleteSubKeyNamed_02
     self new testDeleteSubKeyNamed_02
    "

    "Created: / 30-01-2019 / 15:42:01 / svestkap"
    "Modified (format): / 01-02-2019 / 15:00:13 / svestkap"
!

testDeleteSubKeyNamed_Wow64_32
    "Testing deleting of empty subKey via deleteSubKeyNamed: (only on x64 systems)
     Wow subsystem enables running 32bit applications on 64bit windows"
    | windowsVersion returnValue testingRegistryPath |

    windowsVersion := Win32OperatingSystem registryEntry key: windowsDetailsRegistryPath.
    self skipIf: (windowsVersion valueNamed: 'BuildLabEx') isNil description: 'Skipping test the registry key does not exist.  Happens in some ancient Windows (XP)'.
    self skipIf: ((windowsVersion valueNamed: 'BuildLabEx') includesString: 'x86')  description: 'Skip test if on 32bit Windows (x86)'.  "/ amd64 for x64 Windows

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    "/ if successfully deteted -> true 
    returnValue := testingRegistryPath deleteSubKeyNamed: ' ルすしか_empty' flags:#KEY_WOW64_32KEY.
    self assert: returnValue

    "
     self run:#testDeleteSubKeyNamed_Wow64_32
     self new testDeleteSubKeyNamed_Wow64_32
    "

    "Created: / 07-12-2018 / 14:56:39 / svestkap"
    "Modified: / 12-02-2019 / 14:47:25 / svestkap"
!

testDeleteSubKeyNamed_Wow64_64
    "Testing deleting of empty subKey via deleteSubKeyNamed: (only on x64 systems)
     Wow subsystem enables running 32bit applications on 64bit windows"
    | windowsVersion returnValue testingRegistryPath |
    
    windowsVersion := Win32OperatingSystem registryEntry key: windowsDetailsRegistryPath.
    self skipIf: (windowsVersion valueNamed: 'BuildLabEx') isNil description: 'Skipping test the registry key does not exist.  Happens in some ancient Windows (XP)'.
    self skipIf: ((windowsVersion valueNamed: 'BuildLabEx') includesString: 'x86')  description: 'Skip test if on 32bit Windows (x86)'.  "/ amd64 for x64 Windows
                                                                   
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.   
    "/ if successfully deteted -> true 
    returnValue := testingRegistryPath deleteSubKeyNamed: ' ルすしか_empty' flags:#KEY_WOW64_64KEY.
    self assert: returnValue
 
    "
     self run:#testDeleteSubKeyNamed_Wow64_64
     self new testDeleteSubKeyNamed_Wow64_64
    "

    "Created: / 07-12-2018 / 14:55:03 / svestkap"
    "Modified: / 12-02-2019 / 14:47:30 / svestkap"
!

testDeleteValueNamed_REG_BINARY
    "Testing if REG_BINARY value name is correctly deleted via deleteValueNamed:"
    | readData testingRegistryPath registryValueName deleteResult |

    testingRegistryPath := Win32OperatingSystem registryEntry key: (registryPath, '\', ' ルすしか').
    registryValueName := 'non-zero'.

    readData := testingRegistryPath valueNamed: registryValueName.
    self assert: readData notEmptyOrNil.

    deleteResult := testingRegistryPath deleteValueNamed: registryValueName.      
    self assert: deleteResult.

    readData := testingRegistryPath valueNamed: registryValueName.
    self assert: readData isEmptyOrNil    

    "
     self run:#testDeleteValueNamed_REG_BINARY
     self new testDeleteValueNamed_REG_BINARY
    "

    "Created: / 06-12-2018 / 13:56:35 / svestkap"
    "Modified: / 12-02-2019 / 14:49:58 / svestkap"
!

testDeleteValueNamed_REG_DWORD
    "Testing if REG_DWORD value name is correctly deleted via deleteValueNamed:"
    | readData testingRegistryPath registryValueName deleteResult |

    testingRegistryPath := Win32OperatingSystem registryEntry key: (registryPath, '\', ' ルすしか').
    registryValueName := 'dword_value'.

    readData := testingRegistryPath valueNamed: registryValueName.
    self assert: readData notEmptyOrNil.
    
    deleteResult := testingRegistryPath deleteValueNamed: registryValueName.      
    self assert: deleteResult.
    
    readData := testingRegistryPath valueNamed: registryValueName.
    self assert: readData isEmptyOrNil    

    "
     self run:#testDeleteValueNamed_REG_DWORD
     self new testDeleteValueNamed_REG_DWORD
    "

    "Created: / 06-12-2018 / 09:09:24 / svestkap"
    "Modified: / 12-02-2019 / 14:50:03 / svestkap"
!

testDeleteValueNamed_REG_EXPAND_SZ
    "Testing if REG_EXPAND_SZ value name is correctly deleted via deleteValueNamed:"  
    | readData testingRegistryPath registryValueName deleteResult |

    testingRegistryPath := Win32OperatingSystem registryEntry key: (registryPath, '\', ' ルすしか').
    registryValueName := ' č ルすしか'.

    readData := testingRegistryPath valueNamed: registryValueName.
    self assert: readData notEmptyOrNil.
    
    deleteResult := testingRegistryPath deleteValueNamed: registryValueName.      
    self assert: deleteResult.
    
    readData := testingRegistryPath valueNamed: registryValueName.
    self assert: readData isEmptyOrNil    

    "
     self run:#testDeleteValueNamed_REG_EXPAND_SZ
     self new testDeleteValueNamed_REG_EXPAND_SZ
    "

    "Created: / 06-12-2018 / 13:54:53 / svestkap"
    "Modified: / 12-02-2019 / 14:50:06 / svestkap"
!

testDeleteValueNamed_REG_QWORD
    "Testing if REG_QWORD value name is correctly deleted via deleteValueNamed:"  
    | readData testingRegistryPath registryValueName deleteResult |        

    testingRegistryPath := Win32OperatingSystem registryEntry key: (registryPath, '\', ' ルすしか').
    registryValueName := 'qword_max'.
    
    readData := testingRegistryPath valueNamed: registryValueName.
    self assert: readData notEmptyOrNil.
    
    deleteResult := testingRegistryPath deleteValueNamed: registryValueName.      
    self assert: deleteResult.
    
    readData := testingRegistryPath valueNamed: registryValueName.
    self assert: readData isEmptyOrNil    

    "
     self run:#testDeleteValueNamed_REG_QWORD
     self new testDeleteValueNamed_REG_QWORD
    "

    "Created: / 06-12-2018 / 13:55:46 / svestkap"
    "Modified: / 11-02-2019 / 13:56:54 / svestkap"
!

testDeleteValueNamed_REG_SZ_01
    "Testing if REG_SZ value name is correctly deleted via deleteValueNamed:"    
    | readData testingRegistryPath registryValueName deleteResult |

    testingRegistryPath := Win32OperatingSystem registryEntry key: (registryPath, '\', ' ルすしか').
    registryValueName := ' ř ž č ル.          '.

    readData := testingRegistryPath valueNamed: registryValueName.
    self assert: readData notEmptyOrNil.
    
    deleteResult := testingRegistryPath deleteValueNamed: registryValueName.      
    self assert: deleteResult.
    
    readData := testingRegistryPath valueNamed: registryValueName.
    self assert: readData isEmptyOrNil    

    "
     self run:#testDeleteValueNamed_REG_SZ_01
     self new testDeleteValueNamed_REG_SZ_01
    "

    "Created: / 30-01-2019 / 15:23:27 / svestkap"
    "Modified: / 12-02-2019 / 14:50:11 / svestkap"
!

testDeleteValueNamed_REG_SZ_02
    "Testing if REG_SZ value name is correctly deleted via deleteValueNamed:"    
    | readData testingRegistryPath registryValueName |

    testingRegistryPath := Win32OperatingSystem registryEntry key: (registryPath, '\', ' ルすしか').
    registryValueName := ' ř ž č ル.          '.

    readData := testingRegistryPath valueNamed: registryValueName.
    self assert: readData notEmptyOrNil.
    
    self should: [ testingRegistryPath deleteValueNamed: 88 ] 
         raise: Error
         suchThat: [ :e | e messageText = 'nameString is not a string!!' ]
         
    "
     self run:#testDeleteValueNamed_REG_SZ_02
     self new testDeleteValueNamed_REG_SZ_02
    "

    "Created: / 30-01-2019 / 15:23:10 / svestkap"
    "Modified: / 12-02-2019 / 14:50:15 / svestkap"
!

testDeleteValueNamed_defaultValue_01
    "Testing if (Default) value gets correctly deleted via deleteValueNamed:"    
    | readData registryValueName testingRegistryPath deleteResult|

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.        
    registryValueName := ''.

    readData := testingRegistryPath valueNamed: registryValueName.    
    self assert: readData notEmptyOrNil.
    self assert: readData = 'しか OMG'.
    
    deleteResult := testingRegistryPath deleteValueNamed: registryValueName.       
    self assert: deleteResult.
    
    readData := testingRegistryPath valueNamed: registryValueName.
    self assert: readData isEmptyOrNil    

    "
     self run:#testDeleteValueNamed_defaultValue_01
     self new testDeleteValueNamed_defaultValue_01
    "

    "Created: / 06-12-2018 / 14:04:16 / svestkap"
    "Modified: / 12-02-2019 / 14:50:19 / svestkap"
!

testDeleteValueNamed_defaultValue_02
    "Testing if deleting (Default) empty gets false via deleteValueNamed:"    
    | readData registryValueName testingRegistryPath deleteResult|

    testingRegistryPath := Win32OperatingSystem registryEntry key: (registryPath, '\', ' ルすしか').       
    registryValueName := ''.

    readData := testingRegistryPath valueNamed: registryValueName.    
    self assert: readData isEmptyOrNil.
    
    deleteResult := testingRegistryPath deleteValueNamed: registryValueName.       
    self assert: deleteResult not.

    "
     self run:#testDeleteValueNamed_defaultValue_02
     self new testDeleteValueNamed_defaultValue_02
    "

    "Created: / 06-12-2018 / 14:01:38 / svestkap"
    "Modified: / 12-02-2019 / 14:50:22 / svestkap"
!

testDeleteValueNamed_nonStringValue
    "Testing if trying to delete a key with non-string name raises an error"
    | testingRegistryPath registryValueName |

    testingRegistryPath := Win32OperatingSystem registryEntry key: (registryPath, '\', ' ルすしか').
    registryValueName := 11.
    
    self should: [ testingRegistryPath deleteValueNamed: registryValueName ] raise: Error
        suchThat: [ :e | e messageText = 'nameString is not a string!!' ]    

    "
     self run:#testDeleteValueNamed_nonStringValue
     self new testDeleteValueNamed_nonStringValue
    "

    "Created: / 01-02-2019 / 15:02:57 / svestkap"
! !

!Win32OperatingSystemTest methodsFor:'tests-unicodeDeleteEnumeration'!

testDeleteSubKeyNamed_deletingMultipleSubKeys
    "Testing deleting whole tree of subKeys based on subKey path size via deleteSubKeyNamed:"
    | readData returnValue testingRegistryPath |

    readData := OrderedDictionary new.     
    testingRegistryPath := Win32OperatingSystem registryEntry key:  (registryPath, '\', ' ルすしか_testing_delete').

    testingRegistryPath allSubKeysDo: [ :subEntry |
        readData at: subEntry path put: subEntry
    ].        
    
    "/ sorting based on path size
    readData sort: [ :firstRegistryPath :secondRegistryPath | 
        firstRegistryPath size <  secondRegistryPath size 
    ].    
    
    "/ sorting the path size (max -> min)
    readData reverse.      
    
    "/ deleting all the subKeys (even those that have some value names!!)
    readData valuesDo: [ :registryEntry |
        | tempRegistryEntry |
        tempRegistryEntry := Win32OperatingSystem registryEntry key: (registryEntry path copyUpToLast: $\).
        returnValue := tempRegistryEntry deleteSubKeyNamed: (registryEntry path copyAfterLast: $\).
        self assert: returnValue 
    ].
    
    "/ if successfully deteted -> true 
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    returnValue := testingRegistryPath deleteSubKeyNamed: ' ルすしか_testing_delete'.
    self assert: returnValue
 
    "
     self run:#testDeleteSubKeyNamed_deletingMultipleSubKeys
     self new testDeleteSubKeyNamed_deletingMultipleSubKeys
    "

    "Created: / 07-12-2018 / 10:54:34 / svestkap"
    "Modified: / 12-02-2019 / 14:50:55 / svestkap"
! !

!Win32OperatingSystemTest methodsFor:'tests-unicodeRead'!

testReadSubKeyAtIndex_01
    "Reading subKeys at certain index
     WARNING: subKeyAtIndex: is zero based!!!!!!"
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readData := testingRegistryPath subKeyAtIndex: 0.

    self assert: readData notEmptyOrNil.
    self assert: (readData path copyAfterLast: $\) = ' ルすしか'

    "
     self run:#testReadSubKeyAtIndex_01
     self new testReadSubKeyAtIndex_01
    "

    "Created: / 11-12-2018 / 14:51:12 / svestkap"
    "Modified (format): / 12-02-2019 / 14:51:43 / svestkap"
!

testReadSubKeyAtIndex_02
    "Reading subKeys at certain index - reading non-existent subKey
     WARNING: subKeyAtIndex: is zero based!!!!!!"
    | readData testingRegistryPath |
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readData := testingRegistryPath subKeyAtIndex: 10.

    self assert: readData isNil

    "
     self run:#testReadSubKeyAtIndex_02
     self new testReadSubKeyAtIndex_02
    "

    "Created: / 11-12-2018 / 14:49:03 / svestkap"
    "Modified (format): / 12-02-2019 / 14:51:39 / svestkap"
!

testReadSubKeyAtIndex_03
    "Reading subKeys via a String - should raise an error"
    | testingRegistryPath |
 
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    
    self should: [ testingRegistryPath subKeyAtIndex: 'keyName' ] 
         raise: Error 
         suchThat: [ :e | e messageText = 'subKeyIndex is not an integer!!' ].               

    "
     self run:#testReadSubKeyAtIndex_03
     self new testReadSubKeyAtIndex_03
    "

    "Created: / 01-02-2019 / 15:45:35 / svestkap"
!

testReadSubKeyAtIndex_04
    "Reading subKeys via a Float - should raise an error"
    | testingRegistryPath |
 
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    
    self should: [ testingRegistryPath subKeyAtIndex: 1.1 ] 
         raise: Error 
         suchThat: [ :e | e messageText = 'subKeyIndex is not an integer!!' ].               

    "
     self run:#testReadSubKeyAtIndex_04
     self new testReadSubKeyAtIndex_04
    "

    "Created: / 01-02-2019 / 15:48:14 / svestkap"
!

testReadSubKeyAtIndex_MaxPath
    "Reading subKeyAtIndex with max Path
     Note: This test acually breaks the limit that Microsoft specified in MSDN - registry key name should be maximum 255 characters including absolute path
       MSDN link: https://docs.microsoft.com/en-us/windows/desktop/sysinfo/registry-element-size-limits"
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: 
        (registryPath,'\', ' ルすしか\256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end').        
    
    readData := testingRegistryPath subKeyAtIndex: 0.

    self assert: readData path notEmptyOrNil.
    self assert:(readData path endsWith: '|end').    
       
    "/ this is maximum path size which can be reached if the SubKey is reached via index
    self assert: (readData path copyAfterLast: $\) size = 256.
    
    "
     self run:#testReadSubKeyAtIndex_MaxPath
     self new testReadSubKeyAtIndex_MaxPath
    "

    "Created: / 05-12-2018 / 12:39:54 / svestkap"
    "Modified (comment): / 16-06-2020 / 13:27:59 / svestkap"
!

testReadSubKeyNamesAndClassesAtIndex_01
    "Reading SubKeyNamesAndClasses - reading non-existent subKey"
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: 
        (registryPath,'\', ' ルすしか\256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end').        
    
    readData := testingRegistryPath subKeyNameAndClassAtIndex: 10.

    self assert: readData isNil.        
    "
     self run:#testReadSubKeyNamesAndClassesAtIndex_01
     self new testReadSubKeyNamesAndClassesAtIndex_01
    "

    "Created: / 11-12-2018 / 14:49:48 / svestkap"
    "Modified: / 12-02-2019 / 14:51:56 / svestkap"
!

testReadSubKeyNamesAndClassesAtIndex_02
    "Reading SubKeyNamesAndClasses via String - should raise an error"
    | testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: 
        (registryPath,'\', ' ルすしか\256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end').        

    self should: [ testingRegistryPath subKeyNameAndClassAtIndex: 'asString' ] 
         raise: Error 
         suchThat: [ :e | e messageText = 'subKeyIndex is not an integer!!' ]
         
    "
     self run:#testReadSubKeyNamesAndClassesAtIndex_02
     self new testReadSubKeyNamesAndClassesAtIndex_02
    "

    "Created: / 01-02-2019 / 15:48:02 / svestkap"
!

testReadSubKeyNamesAndClassesAtIndex_03
    "Reading SubKeyNamesAndClasses via Float - should raise an error"
    | testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: 
        (registryPath,'\', ' ルすしか\256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end').        

    self should: [ testingRegistryPath subKeyNameAndClassAtIndex: 1.1 ] 
         raise: Error 
         suchThat: [ :e | e messageText = 'subKeyIndex is not an integer!!' ]
         
    "
     self run:#testReadSubKeyNamesAndClassesAtIndex_03
     self new testReadSubKeyNamesAndClassesAtIndex_03
    "

    "Created: / 01-02-2019 / 15:51:03 / svestkap"
!

testReadSubKeyNamesAndClassesAtIndex_MaxPath
    "Reading SubKeyNamesAndClasses with max Path
     Note: This test acually breaks the limit that Microsoft specified in MSDN - registry key name should be maximum 255 characters including absolute path
       MSDN link: https://docs.microsoft.com/en-us/windows/desktop/sysinfo/registry-element-size-limits"
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: 
        (registryPath,'\', ' ルすしか\256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end').        
    
    readData := testingRegistryPath subKeyNameAndClassAtIndex: 0.

    self assert: readData notEmptyOrNil.
    self assert:(readData first endsWith: '|end').
    self assert: readData first = '256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end'.        

    "/ this is maximum path size which can be reached if the SubKey is reached via index
    self assert: ((testingRegistryPath path copyUpTo: $-) size + readData first size) = 293.
    
    "
     self run:#testReadSubKeyNamesAndClassesAtIndex_MaxPath
     self new testReadSubKeyNamesAndClassesAtIndex_MaxPath
    "

    "Created: / 05-12-2018 / 12:40:08 / svestkap"
    "Modified: / 16-06-2020 / 13:49:57 / svestkap"
!

testReadTooLongPath
    "Trying to read too long path - nil is returned"
    | testingRegistryPath |
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: 
            (registryPath,'\', ' ルすしか\256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa
            |end','\','256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end').        

    self assert: testingRegistryPath isNil            
    
    "
     self run:#testReadTooLongPath
     self new testReadTooLongPath
    "

    "Created: / 22-11-2018 / 11:19:51 / svestkap"
    "Modified (comment): / 01-02-2019 / 14:58:15 / svestkap"
!

testReadValueNameAtIndex_01
    "Reading values (#valueNameAtIndex:) at certain index
     WARNING: #valueNameAtIndex: is zero based!!!!!!
     Note: This test acually breaks the limit that Microsoft specified in MSDN - registry key name should be maximum 255 characters including absolute path
       MSDN link: https://docs.microsoft.com/en-us/windows/desktop/sysinfo/registry-element-size-limits" 
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: (registryPath,'\', ' ルすしか').
    readData := testingRegistryPath valueNameAtIndex: 1.

    self assert: readData notEmptyOrNil.
    self assert: readData = 'しかき    '

    "
     self run:#testReadValueNameAtIndex
     self new testReadValueNameAtIndex
    "

    "Created: / 11-12-2018 / 14:54:37 / svestkap"
    "Modified: / 12-02-2019 / 14:52:19 / svestkap"
!

testReadValueNameAtIndex_02
    "Reading values (#valueNameAtIndex:) at certain index - non-existent value" 
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: (registryPath,'\', ' ルすしか').
    readData := testingRegistryPath valueNameAtIndex: 100.

    self assert: readData isNil    

    "
     self run:#testReadValueNameAtIndex_02
     self new testReadValueNameAtIndex_02
    "

    "Created: / 11-12-2018 / 14:54:29 / svestkap"
    "Modified: / 12-02-2019 / 14:52:25 / svestkap"
!

testReadValueNameAtIndex_03    
    "Reading values (#valueNameAtIndex:) via String - should raise an error"
    | testingRegistryPath |
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: (registryPath,'\', ' ルすしか').

    self should: [ testingRegistryPath valueNameAtIndex: 'stringInsteadOfIndex' ] 
         raise: Error 
         suchThat: [ :e | e messageText = 'valueIndex is not an integer!!' ]
                                                                                     
    "
     self run:#testReadValueNameAtIndex_03
     self new testReadValueNameAtIndex_03
    "

    "Created: / 01-02-2019 / 15:52:27 / svestkap"
!

testReadValueNameAtIndex_04    
    "Reading values (#valueNameAtIndex:) via Float - should raise an error"
    | testingRegistryPath |
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: (registryPath,'\', ' ルすしか').

    self should: [ testingRegistryPath valueNameAtIndex: 1.1 ] 
         raise: Error 
         suchThat: [ :e | e messageText = 'valueIndex is not an integer!!' ]
                                                                                     
    "
     self run:#testReadValueNameAtIndex_04
     self new testReadValueNameAtIndex_04
    "

    "Created: / 01-02-2019 / 15:55:03 / svestkap"
!

testReadValueNamed_REG_BINARY_01
    "Testing if REG_BINARY values are read correctly via valueNamed:"
    | readData testingRegistryPath |
        
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
     
    readData := testingRegistryPath valueNamed: 'zero'.
        
    self assert: readData = ByteArray new.

    "
     self run:#testReadValueNamed_REG_BINARY_01
     self new testReadValueNamed_REG_BINARY_01
    "

    "Created: / 16-11-2018 / 12:37:50 / svestkap"
    "Modified (format): / 01-02-2019 / 13:28:15 / svestkap"
!

testReadValueNamed_REG_BINARY_02
    "Testing if REG_BINARY values are read correctly via valueNamed:"
    | testingRegistryPath readData readDataHex |
        
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
     
    readData := testingRegistryPath valueNamed: 'non-zero'.        
    readDataHex := readData hexPrintStringWithSeparator: $|.
    
    self assert: readData = #[17 16]. "/ ByteArray
    self assert: readDataHex = '11|10' "/ hex    
    
    "
     self run:#testReadValueNamed_REG_BINARY_02
     self new testReadValueNamed_REG_BINARY_02
    "

    "Created: / 16-11-2018 / 12:39:33 / svestkap"
    "Modified (format): / 01-02-2019 / 13:28:21 / svestkap"
!

testReadValueNamed_REG_DWORD_01
    "Testing if REG_DWORD values are read correctly via valueNamed:"
    | readData testingRegistryPath |
        
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.     
    readData := testingRegistryPath valueNamed: 'dword_value'.
        
    self assert: readData = 9135.

    "
     self run:#testReadValueNamed_REG_DWORD_01
     self new testReadValueNamed_REG_DWORD_01
    "

    "Created: / 16-11-2018 / 12:24:26 / svestkap"
    "Modified: / 12-02-2019 / 14:52:58 / svestkap"
!

testReadValueNamed_REG_DWORD_02
    "Testing if REG_DWORD values are read correctly via valueNamed:"
    | readData testingRegistryPath |
            
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.     
    readData := testingRegistryPath valueNamed: 'き'.
        
    self assert: readData = 591541423.

    "
     self run:#testReadValueNamed_REG_DWORD_02
     self new testReadValueNamed_REG_DWORD_02
    "

    "Created: / 16-11-2018 / 12:24:43 / svestkap"
    "Modified: / 12-02-2019 / 14:53:05 / svestkap"
!

testReadValueNamed_REG_EXPAND_SZ_01
    "Testing if REG_EXPAND_SZ values are read correctly via valueNamed:"
    | readData testingRegistryPath |
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.     
    readData := testingRegistryPath valueNamed: ' č ルすしか'.
        
    self assert: readData = '''Testing Unicode chars ř ž č ルすしかき'').          '. 

    "
     self run:#testReadValueNamed_REG_EXPAND_SZ_01
     self new testReadValueNamed_REG_EXPAND_SZ_01
    "

    "Created: / 16-11-2018 / 12:27:58 / svestkap"
    "Modified: / 12-02-2019 / 14:53:11 / svestkap"
!

testReadValueNamed_REG_EXPAND_SZ_02
    "Testing if REG_EXPAND_SZ values are read correctly via valueNamed:"
    | readData testingRegistryPath |
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.     
    readData := testingRegistryPath valueNamed: 'Ugh'.
        
    self assert: readData = '''Testing Unicode chars ř ž č ルすしかき'').          '. 

    "
     self run:#testReadValueNamed_REG_EXPAND_SZ_02
     self new testReadValueNamed_REG_EXPAND_SZ_02
    "

    "Created: / 16-11-2018 / 12:29:52 / svestkap"
    "Modified: / 12-02-2019 / 14:53:16 / svestkap"
!

testReadValueNamed_REG_MULTI_SZ_01
    "Testing if REG_MULTI_SZ values are read correctly via valueNamed:"
    | readData testingRegistryPath |
        
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
     
    readData := testingRegistryPath valueNamed: 'Font_Leelawadee UI Bold'.
        
    self assert: readData = #('SEGOEUIB.TTF,Segoe UI Bold,110,82' 'SEGOEUIB.TTF,Segoe UI Bold' 'MEIRYOB.TTC,Meiryo UI Bold,120,96' 
                              'MEIRYOB.TTC,Meiryo UI Bold' 'MSJHBD.TTC,Microsoft JhengHei UI Bold,120,96' 'MSJHBD.TTC,Microsoft JhengHei UI Bold'
                              'MSYHBD.TTC,Microsoft YaHei UI Bold,128,96' 'MSYHBD.TTC,Microsoft YaHei UI Bold' 'MALGUNBD.TTF,Malgun Gothic Bold,118,96'
                              'MALGUNBD.TTF,Malgun Gothic Bold' 'YUGOTHB.TTC,Yu Gothic UI Bold,128,96' 'YUGOTHB.TTC,Yu Gothic UI Bold' 'SEGUISYM.TTF,Segoe UI Symbol') 

    "
     self run:#testReadValueNamed_REG_MULTI_SZ_01
     self new testReadValueNamed_REG_MULTI_SZ_01
    "

    "Created: / 16-11-2018 / 12:30:24 / svestkap"
    "Modified (format): / 01-02-2019 / 13:28:46 / svestkap"
!

testReadValueNamed_REG_MULTI_SZ_02
    "Testing if REG_MULTI_SZ values are read correctly via valueNamed:"
    | readData testingRegistryPath |
        
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
     
    readData := testingRegistryPath valueNamed: 'ř ž č ルすしか'.
        
    self assert: readData = #('''Testing Unicode chars ř ž č ルすしかき'')'
                              'SEGOEUIB.TTF,Segoe UI Bold,110,82' 'SEGOEUIB.TTF,Segoe UI Bold' 'MEIRYOB.TTC,Meiryo UI Bold,120,96' 
                              'MEIRYOB.TTC,Meiryo UI Bold' 'MSJHBD.TTC,Microsoft JhengHei UI Bold,120,96' 'MSJHBD.TTC,Microsoft JhengHei UI Bold'
                              'MSYHBD.TTC,Microsoft YaHei UI Bold,128,96' 'MSYHBD.TTC,Microsoft YaHei UI Bold' 'MALGUNBD.TTF,Malgun Gothic Bold,118,96'
                              'MALGUNBD.TTF,Malgun Gothic Bold' 'YUGOTHB.TTC,Yu Gothic UI Bold,128,96' 'YUGOTHB.TTC,Yu Gothic UI Bold' 'SEGUISYM.TTF,Segoe UI Symbol') 

    "
     self run:#testReadValueNamed_REG_MULTI_SZ_02
     self new testReadValueNamed_REG_MULTI_SZ_02
    "

    "Created: / 16-11-2018 / 12:35:57 / svestkap"
    "Modified (format): / 01-02-2019 / 13:28:52 / svestkap"
!

testReadValueNamed_REG_MULTI_SZ_03
    "Testing if empty REG_MULTI_SZ value is read correctly via valueNamed:"
    | readData testingRegistryPath |
        
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
     
    readData := testingRegistryPath valueNamed: 'testEmptyMultiSZ'.
    
    self assert: readData isEmpty

    "
     self run:#testReadValueNamed_REG_MULTI_SZ_03
     self new testReadValueNamed_REG_MULTI_SZ_03
    "

    "Created: / 03-12-2018 / 10:59:48 / svestkap"
    "Modified (format): / 01-02-2019 / 13:28:58 / svestkap"
!

testReadValueNamed_REG_QWORD_01
    "Testing if REG_QWORD values are read correctly via valueNamed:.
     The read value is a QWORD maximum value"
    | readData testingRegistryPath |    
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.    
    readData := testingRegistryPath valueNamed: 'qword_max'.
        
    self assert: readData = 18446744073709551615.

    "
     self run:#testReadValueNamed_REG_QWORD_01
     self new testReadValueNamed_REG_QWORD_01
    "

    "Created: / 16-11-2018 / 12:25:47 / svestkap"
    "Modified: / 11-02-2019 / 13:46:18 / svestkap"
!

testReadValueNamed_REG_QWORD_02
    "Testing if REG_QWORD values are read correctly via valueNamed:"
    | readData testingRegistryPath |        
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.    
    readData := testingRegistryPath valueNamed: 'qwordvalue'.
        
    self assert: readData = 8751636011737964973.

    "
     self run:#testReadValueNamed_REG_QWORD_02
     self new testReadValueNamed_REG_QWORD_02
    "

    "Created: / 16-11-2018 / 12:26:23 / svestkap"
    "Modified: / 11-02-2019 / 13:46:07 / svestkap"
!

testReadValueNamed_REG_QWORD_03
    "Testing if REG_QWORD values are read correctly via valueNamed:"
    | readData testingRegistryPath |        
        
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.    
    readData := testingRegistryPath valueNamed: 'すし'.
    
    "/ normalize if LargeInteger    
    readData class == LargeInteger ifTrue: [
        readData := readData copy compressed
    ].

    self assert: readData = 44527.
    
    "
     self run:#testReadValueNamed_REG_QWORD_03
     self new testReadValueNamed_REG_QWORD_03
    "

    "Created: / 16-11-2018 / 12:27:17 / svestkap"
    "Modified (format): / 11-02-2019 / 14:17:28 / svestkap"
!

testReadValueNamed_REG_SZ_01
    "Testing if REG_SZ values are read correctly via valueNamed:"
    | readData testingRegistryPath |
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.     
    readData := testingRegistryPath valueNamed: 'bledesu'.
    
    self assert: readData = '''Testing Unicode chars ř ž č ルすしかき'').          '.
    
    "
     self run:#testReadValueNamed_REG_SZ_01
     self new testReadValueNamed_REG_SZ_01
    "

    "Created: / 16-11-2018 / 12:14:59 / svestkap"
    "Modified: / 12-02-2019 / 14:53:38 / svestkap"
!

testReadValueNamed_REG_SZ_02
    "Testing if REG_SZ values are read correctly via valueNamed:"
    | readData testingRegistryPath |
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.     
    readData := testingRegistryPath valueNamed: ' ř ž č ル.          '.
        
    self assert: readData = 'Testing Unicode chars ř ž č ルすしかき'.    

    "
     self run:#testReadValueNamed_REG_SZ_02
     self new testReadValueNamed_REG_SZ_02
    "

    "Created: / 16-11-2018 / 12:15:17 / svestkap"
    "Modified: / 12-02-2019 / 14:53:44 / svestkap"
!

testReadValueNamed_REG_SZ_03
    "Testing if REG_SZ values are read correctly via valueNamed:"
    | readData testingRegistryPath |
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.     
    readData := testingRegistryPath valueNamed: 'しかき    '.
        
    self assert: readData = 'Testus gradus'.

    "
     self run:#testReadValueNamed_REG_SZ_03
     self new testReadValueNamed_REG_SZ_03
    "

    "Created: / 16-11-2018 / 12:21:59 / svestkap"
    "Modified: / 12-02-2019 / 14:53:51 / svestkap"
!

testReadValueNamed_REG_SZ_04
    "Testing if empty REG_SZ value is read correctly via valueNamed:"
    | readData testingRegistryPath |
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.     
    readData := testingRegistryPath valueNamed: 'emptyToTest'.
    
    self assert: readData isEmpty.
    
    "
     self run:#testReadValueNamed_REG_SZ_04
     self new testReadValueNamed_REG_SZ_04
    "

    "Created: / 03-12-2018 / 10:56:11 / svestkap"
    "Modified: / 12-02-2019 / 14:53:56 / svestkap"
!

testReadValueNamed_nonStringValue
    "Testing reading non-string value from Registry via valueNamed raises an error"    
    | testingRegistryPath |
        
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    self should: [ testingRegistryPath valueNamed: 11 ] 
         raise: Error 
         suchThat: [ :e | e messageText = 'nameString is not a string!!' ].        

    "
     self run:#testReadValueNamed_nonStringValue
     self new testReadValueNamed_nonStringValue
    "

    "Created: / 05-12-2018 / 12:40:31 / svestkap"
    "Modified (format): / 30-01-2019 / 15:30:21 / svestkap"
!

testValueTypeAndSize_01
    "Testing if an error is returned when number is used instead of string as method parammeter at valueTypeAndSize:"
    | testingRegistryPath |
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    self should: [ testingRegistryPath valueTypeAndSize: 55 ] 
         raise: Error 
         suchThat: [ :e | e messageText = 'nameString is not a string!!' ].                                                                          
    
    "
     self run:#testValueTypeAndSize_01
     self new testValueTypeAndSize_01
    "

    "Created: / 30-01-2019 / 17:15:49 / svestkap"
!

testValueTypeAndSize_REG_BINARY_01
    "Testing if #REG_BINARY type returns correct size in bytes"
    | testingRegistryPath readData testingData |

    testingData := Dictionary new.            
    testingData at: #'REG_BINARY' put: 2. "/ [bytes] - testing registry contains #[17 16]    
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readData := testingRegistryPath valueTypeAndSize: 'non-zero'.
    
    self assert: readData keys first = #REG_BINARY.  
    self assert: (readData at: #'REG_BINARY') = (testingData at: #'REG_BINARY')    
    
    "
     self run:#testValueTypeAndSize_REG_BINARY_01
     self new testValueTypeAndSize_REG_BINARY_01
    "

    "Created: / 31-01-2019 / 15:47:05 / svestkap"
!

testValueTypeAndSize_REG_DWORD_01
    "Testing if #REG_DWORD type returns correct size in bytes"
    | testingData testingRegistryType testingRegistryPath readData |

    testingData := Dictionary new.
    testingRegistryType := UninterpretedBytes isBigEndian ifTrue: [ #REG_DWORD_BIG_ENDIAN ]
                                                         ifFalse: [ #REG_DWORD_LITTLE_ENDIAN ].
    testingData at: testingRegistryType put: 4. "/ 32bits = 4 bytes - testing registry contains 0xffffffff 
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readData := testingRegistryPath valueTypeAndSize: 'dword_value'.
    
    self assert: readData keys first = testingRegistryType.  
    self assert: (readData at: testingRegistryType) = (testingData at: testingRegistryType)    
    
    "
     self run:#testValueTypeAndSize_REG_DWORD_01
     self new testValueTypeAndSize_REG_DWORD_01
    "

    "Created: / 31-01-2019 / 16:03:52 / svestkap"
    "Modified (comment): / 01-02-2019 / 15:13:01 / svestkap"
!

testValueTypeAndSize_REG_EXPAND_SZ_01
    "Testing if #REG_EXPAND_SZ type returns expected string size"
    | testingData testingRegistryType testingRegistryPath readData |

    testingData := Dictionary new.
    testingRegistryType := #REG_EXPAND_SZ.
    testingData at: testingRegistryType put: 47. "/ expected string size
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readData := testingRegistryPath valueTypeAndSize: ' č ルすしか'.
    
    self assert: readData keys first = testingRegistryType.  
    self assert: (readData at: testingRegistryType) = (testingData at: testingRegistryType)    
    
    "
     self run:#testValueTypeAndSize_REG_EXPAND_SZ_01
     self new testValueTypeAndSize_REG_EXPAND_SZ_01
    "

    "Created: / 31-01-2019 / 15:55:35 / svestkap"
    "Modified (comment): / 01-02-2019 / 15:09:26 / svestkap"
!

testValueTypeAndSize_REG_MULTI_SZ_01
    "Testing if #REG_MULTI_SZ type returns correct size in bytes"
    | testingData testingRegistryType testingRegistryPath readData |

    testingData := Dictionary new.
    testingRegistryType :=  #REG_MULTI_SZ.
    testingData at: testingRegistryType put: 974. "/ [bytes] - multiple lines in registry
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readData := testingRegistryPath valueTypeAndSize: 'ř ž č ルすしか'.
    
    self assert: readData keys first = testingRegistryType.  
    self assert: (readData at: testingRegistryType) = (testingData at: testingRegistryType)    
    
    "
     self run:#testValueTypeAndSize_REG_MULTI_SZ_01
     self new testValueTypeAndSize_REG_MULTI_SZ_01
    "

    "Created: / 31-01-2019 / 16:14:31 / svestkap"
!

testValueTypeAndSize_REG_NONE_01
    "Testing if #REG_NONE type returns alwyas 0 as it should"
    | testingRegistryPath readData testingData |

    testingData := Dictionary new.            
    testingData at: #REG_NONE put: 0. "/ #REG_NONE always returns 0
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: (registryPath,'\', '\ ルすしか_testing_delete\reg-none').
    readData := testingRegistryPath valueTypeAndSize: ''.
    
    self assert: readData keys first = #REG_NONE.  
    self assert: (readData at: #'REG_NONE') = (testingData at: #'REG_NONE')    
    
    "
     self run:#testValueTypeAndSize_REG_NONE_01
     self new testValueTypeAndSize_REG_NONE_01
    "

    "Created: / 31-01-2019 / 15:35:37 / svestkap"
    "Modified (comment): / 01-02-2019 / 15:13:27 / svestkap"
!

testValueTypeAndSize_REG_QWORD_01
    "Testing if #REG_QWORD type returns correct size in bytes"
    | testingData testingRegistryType testingRegistryPath readData |    
    
    testingData := Dictionary new.
    testingRegistryType :=  #REG_QWORD.
    testingData at: testingRegistryType put: 8. "/ 64bits = 8bytes - testing registry contains 0xffffffffffffffff 
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readData := testingRegistryPath valueTypeAndSize: 'qword_max'.
    
    self assert: readData keys first = testingRegistryType.  
    self assert: (readData at: testingRegistryType) = (testingData at: testingRegistryType)    
    
    "
     self run:#testValueTypeAndSize_REG_DWORD_01
     self new testValueTypeAndSize_REG_DWORD_01
    "

    "Created: / 31-01-2019 / 16:12:21 / svestkap"
    "Modified: / 11-02-2019 / 13:48:32 / svestkap"
!

testValueTypeAndSize_REG_SZ_01
    "Testing if #REG_SZ type returns expected string size"
    | testingRegistryPath readData testingData |

    testingData := Dictionary new.            
    testingData at: #REG_SZ put: 13.
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    readData := testingRegistryPath valueTypeAndSize: 'しかき    '.
    
    self assert: readData keys first = #REG_SZ.  
    self assert: (readData at: #'REG_SZ') = (testingData at: #'REG_SZ')    
    
    "
     self run:#testValueTypeAndSize_REG_SZ_01
     self new testValueTypeAndSize_REG_SZ_01
    "

    "Created: / 30-01-2019 / 17:13:53 / svestkap"
    "Modified (comment): / 31-01-2019 / 16:01:37 / svestkap"
! !

!Win32OperatingSystemTest methodsFor:'tests-unicodeReadEnumeration'!

testReadAllSubKeysDo_MaxPath
    "Reading via allSubKeysDo (using subKeyAtIndex:)with maximum path length.
     The path suppasses the limit specified by Microsoft - for more information see testReadSubKeyAtIndex_MaxPath_01"
    | readData testingRegistryPath |

    readData := OrderedCollection new.    
    testingRegistryPath := Win32OperatingSystem registryEntry key: 
        (registryPath,'\', ' ルすしか\256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end').        
    
    testingRegistryPath  allSubKeysDo: [ :subEntry |
        readData add: subEntry
    ].     
    
    self assert: readData notEmptyOrNil.    
    self assert: readData size = 3.
    "/ this is normally unreachable subKey (subkey actually called 'unreachable')
    self assert: ((readData at: 2) path copyUpTo: $-) size + ((readData at: 2) path copyAfterLast: $\) size = 48.
    
    readData := readData copy collect: [ :subEntry | subEntry path copyAfterLast: $\ ].

    self assert: readData size = 3.    
    self assert: (readData first endsWith: '|end').
    self assert: readData first size = 256.
    self assert: readData second = 'unreachable'.
    self assert: readData third = 'reachable'.

    "
     self run:#testReadAllSubKeysDo_MaxPath
     self new testReadAllSubKeysDo_MaxPath
    "

    "Created: / 05-12-2018 / 12:40:53 / svestkap"
    "Modified (format): / 16-06-2020 / 13:48:58 / svestkap"
!

testReadRemoteKeyOnHost_01
    "Reading remote registry via remoteKeyOnHost:
     Note: a key must be a predefined key for more see: 
       https://docs.microsoft.com/en-us/windows/desktop/SysInfo/predefined-keys"
    | testingRegistryPath remoteRegistry readData  |
    
    "/ HKEY_CURRENT_USER is one of the predefined keys
    testingRegistryPath := Win32OperatingSystem registryEntry key: 'HKEY_CURRENT_USER'.        
    "/ testing done on localhost
    "Skip testing if the remote registry is unreachable.  With localhost this can happen when 
     the service RemoteRegistry, the service name in Windows 10, is not started."
    [ remoteRegistry := testingRegistryPath remoteKeyOnHost: 'localhost' ] on: OsError do: [ :ex | "/ errorCode => `ex parameter parameter`
        self skipIf: ex parameter parameter = '53' description: 'ERROR_BAD_NETPATH, 53 (0x35) - The network path was not found.'
    ].
    readData := remoteRegistry subKeys.
    
    readData := readData copy collect: [ :subEntry | (subEntry path copyAfterLast: $\) asLowercase ].
    
    self assert: readData notEmptyOrNil.    
    self assert: (readData includes: 'software').    

    "
     self run:#testReadRemoteKeyOnHost_01
     self new testReadRemoteKeyOnHost_01
    "

    "Created: / 31-01-2019 / 12:11:06 / svestkap"
    "Modified (comment): / 01-02-2019 / 14:51:09 / svestkap"
!

testReadRemoteKeyOnHost_02
    "Reading remote registry via remoteKeyOnHost: using non-string key name
     Note: a key must be a predefined key for more see: 
       https://docs.microsoft.com/en-us/windows/desktop/SysInfo/predefined-keys"
    | testingRegistryPath |
    
    "/ HKEY_CURRENT_USER is one of the predefined keys
    testingRegistryPath := Win32OperatingSystem registryEntry key: 'HKEY_CURRENT_USER'.            
    self should: [ testingRegistryPath remoteKeyOnHost: 11 ] 
         raise: Error 
         suchThat: [ :e | e messageText = 'hostNameString is not a string!!' ]
    
    "
     self run:#testReadRemoteKeyOnHost_02
     self new testReadRemoteKeyOnHost_02
    "

    "Created: / 31-01-2019 / 12:10:18 / svestkap"
    "Modified (format): / 01-02-2019 / 14:51:23 / svestkap"
!

testReadSubKeyNamesAndClassesDo_MaxPath
    "Reading SubKeyNamesAndClasses with maximum path length.
     The path suppasses the limit specified by Microsoft - for more information see testReadSubKeyNamesAndClassesAtIndex_MaxPath_01"
    | readData testingRegistryPath |

    readData := OrderedDictionary new.    
    testingRegistryPath := Win32OperatingSystem registryEntry key: 
        (registryPath,'\', ' ルすしか\256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end').        
    
    testingRegistryPath  subKeyNamesAndClassesDo: [ :name :className |
        readData at: name put: className.
    ].     

    self assert: readData notEmptyOrNil.
    self assert: readData size = 2.
    self assert: (readData at: 'reachable') isEmpty. "/ the class is empty

    "
     self run:#testReadSubKeyNamesAndClassesDo_MaxPath
     self new testReadSubKeyNamesAndClassesDo_MaxPath
    "

    "Created: / 05-12-2018 / 12:41:31 / svestkap"
    "Modified (comment): / 01-02-2019 / 14:57:00 / svestkap"
!

testReadSubKeysDo_MaxPath
    "Reading data via subKeysDo (using subKeyAtIndex:) with maximum path length.
     The path suppasses the limit specified by Microsoft - for more information see testReadSubKeyAtIndex_MaxPath_01"
    | readData testingRegistryPath |

    readData := OrderedCollection new.    
    testingRegistryPath := Win32OperatingSystem registryEntry key: 
        (registryPath,'\', ' ルすしか\256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end').        
    
    testingRegistryPath subKeysDo: [ :subEntry |
        readData add: subEntry
    ].     
    
    self assert: readData notEmptyOrNil.    
    self assert: readData size = 2.    
    
    readData := readData copy collect: [ :subEntry | subEntry path copyAfterLast: $\ ].

    self assert: readData size = 2.    
    self assert: (readData first endsWith: '|end').
    self assert: readData second = 'reachable'.
    self assert: readData first size = 256.

    "
     self run:#testReadSubKeysDo_MaxPath
     self new testReadSubKeysDo_MaxPath
    "

    "Created: / 05-12-2018 / 12:41:49 / svestkap"
    "Modified: / 16-06-2020 / 13:21:40 / svestkap"
!

testReadSubKeys_MaxPath
    "Reading via subKeys (using subKeyAtIndex:) with maximum path length.
     The path suppasses the limit specified by Microsoft - for more information see testReadSubKeyAtIndex_MaxPath_01"
    | readData testingRegistryPath |
    
    testingRegistryPath := Win32OperatingSystem registryEntry key: 
        (registryPath,'\', ' ルすしか\256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end').        
    
    readData := testingRegistryPath subKeys.
    
    self assert: readData notEmptyOrNil.    
    self assert: readData size = 2.        
    
    readData := readData copy collect: [ :subEntry | subEntry path copyAfterLast: $\ ].

    self assert: readData size = 2.    
    self assert: (readData first endsWith: '|end').
    self assert: readData second = 'reachable'.
    self assert: readData first size = 256. 

    "
     self run:#testReadSubKeys_MaxPath
     self new testReadSubKeys_MaxPath
    "

    "Created: / 05-12-2018 / 12:41:59 / svestkap"
    "Modified: / 16-06-2020 / 13:20:53 / svestkap"
!

testReadValueNamesAndValuesDo_MaxPath
    "Reading data via #valueNamesAndValuesDo: (using #valueNameAtIndex:) with maximum path length.
     The path suppasses the limit specified by Microsoft - for more information see testReadValueNameAtIndex_01"
    | readData testingRegistryPath |

    readData := OrderedDictionary new.    
    testingRegistryPath := Win32OperatingSystem registryEntry key: 
        (registryPath,'\', ' ルすしか\256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end').        
    
    testingRegistryPath valueNamesAndValuesDo: [ :name :value |
        readData at: name put: value
    ].     
    
    self assert: readData notEmptyOrNil.    
    self assert: readData size = 3.    
    self assert: readData first =  ('testing'->' ルすしか').
    self assert: (readData at: 'か')= 2.
    self assert: readData second = 2.
    self assert: (readData at: '256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end') 
        = 'Longer_than_256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|endsdfsdfasdfasdfasdfjlkasdjflkasjdflkjasdlfjaslkdfjlkasdjflkasdflksadlkjsadlfalsdfůlasdjflkasdjflkasjdflkůjasdflůkjasdlůfjalsůkdjflůksd'.
    self assert: readData third = 'Longer_than_256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|endsdfsdfasdfasdfasdfjlkasdjflkasjdflkjasdlfjaslkdfjlkasdjflkasdflksadlkjsadlfalsdfůlasdjflkasdjflkasjdflkůjasdflůkjasdlůfjalsůkdjflůksd'.

    "  
     self run:#testReadValueNamesAndValuesDo_MaxPath
     self new testReadValueNamesAndValuesDo_MaxPath
    "

    "Created: / 05-12-2018 / 12:43:05 / svestkap"
    "Modified (comment): / 01-02-2019 / 14:54:23 / svestkap"
!

testReadValueNamesAndValuesDo_REG_SZ_01
    "Testing if REG_SZ values are read correctly via valueNamesAndValuesDo:"
    | readData testingRegistryPath |
    
    readData := OrderedDictionary new.    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
     
    testingRegistryPath valueNamesAndValuesDo: [ :name :data |
        readData at: name put: data
    ].
    
    self assert: (readData at: 'bledesu') = '''Testing Unicode chars ř ž č ルすしかき'').          '.
    
    "
     self run:#testReadValueNamesAndValuesDo_REG_SZ_01
     self new testReadValueNamesAndValuesDo_REG_SZ_01
    "

    "Created: / 16-11-2018 / 12:15:52 / svestkap"
    "Modified (format): / 01-02-2019 / 13:31:44 / svestkap"
!

testReadValueNamesAndValuesDo_REG_SZ_02
    "Testing if REG_SZ values are read correctly via valueNamesAndValuesDo:"
    | readData testingRegistryPath |
    
    readData := OrderedDictionary new.    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
     
    testingRegistryPath valueNamesAndValuesDo: [ :name :data |
        readData at: name put: data
    ].
    
    self assert: (readData at: ' ř ž č ル.          ') = 'Testing Unicode chars ř ž č ルすしかき'.    

    "
     self run:#testReadValueNamesAndValuesDo_REG_SZ_02
     self new testReadValueNamesAndValuesDo_REG_SZ_02
    "

    "Created: / 05-12-2018 / 12:43:35 / svestkap"
    "Modified (format): / 01-02-2019 / 13:31:48 / svestkap"
!

testReadValueNamesDo_MaxPath
    "Reading data via #valueNamesDo: (using #valueNameAtIndex:)  with maximum path length.
     The path is suppassing the Microsoft limit - for more information see testReadValueNameAtIndex_01"
    | readData readDataValue testingRegistryPath |

    readData := OrderedCollection new.    
    testingRegistryPath := Win32OperatingSystem registryEntry key: 
        (registryPath,'\', ' ルすしか\256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end').        
    
    testingRegistryPath valueNamesDo: [ :subEntry |
        readData add: subEntry
    ].     
    
    self assert: readData notEmptyOrNil.    
    self assert: readData size = 3.    
    self assert: readData first = 'testing'.
    self assert: readData second = 'か'.
    self assert: readData third = '256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end'.
    
    readDataValue := testingRegistryPath valueNamed: readData third.  
    
    "/ MSDN limits: Value name 16,383 characters (@Windows 2000: 260 ANSI characters or 16,383 Unicode characters)
    "/ the following tests 401 characters       
    self assert: readDataValue = 'Longer_than_256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|endsdfsdfasdfasdfasdfjlkasdjflkasjdflkjasdlfjaslkdfjlkasdjflkasdflksadlkjsadlfalsdfůlasdjflkasdjflkasjdflkůjasdflůkjasdlůfjalsůkdjflůksd'.
    "
     self run:#testReadValueNamesDo_MaxPath
     self new testReadValueNamesDo_MaxPath
    "

    "Created: / 05-12-2018 / 12:43:49 / svestkap"
    "Modified (comment): / 01-02-2019 / 14:55:15 / svestkap"
!

testReadValueNames_MaxPath
    "reading via #valueNames (using #valueNameAtIndex:) with max Path
     The path is suppassing the Microsoft limit - for more information see testReadValueNameAtIndex_01"
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: 
        (registryPath,'\', ' ルすしか\256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end').        
    
    readData := testingRegistryPath valueNames.
    
    self assert: readData isArray.
    self assert: readData notEmptyOrNil.    
    self assert: readData size = 3.    
    self assert: readData first = 'testing'.
    self assert: readData second = 'か'.
    self assert: readData third = '256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end'.

    "  
     self run:#testReadValueNames_MaxPath
     self new testReadValueNames_MaxPath
    "

    "Created: / 05-12-2018 / 12:44:16 / svestkap"
    "Modified (format): / 01-02-2019 / 13:31:55 / svestkap"
!

testReadvalueNamesAndValuesDo_MaxPath_01
    "reading via #valueNamesAndValuesDo: (using #valueNameAtIndex:) with max Path
     The path is suppassing the Microsoft limit - for more information see testReadValueNameAtIndex_01"
    | readData testingRegistryPath |

    readData := OrderedDictionary new.    
    testingRegistryPath := Win32OperatingSystem registryEntry key: 
        (registryPath,'\', ' ルすしか\256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end').        
    
    testingRegistryPath valueNamesAndValuesDo: [ :name :value |
        readData at: name put: value
    ].     
    
    self assert: readData notEmptyOrNil.    
    self assert: readData size = 3.    
    self assert: readData first =  ('testing'->' ルすしか').
    self assert: (readData at: 'か')= 2.
    self assert: readData second = 2.
    self assert: (readData at: '256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|end') 
        = 'Longer_than_256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|endsdfsdfasdfasdfasdfjlkasdjflkasjdflkjasdlfjaslkdfjlkasdjflkasdflksadlkjsadlfalsdfůlasdjflkasdjflkasjdflkůjasdflůkjasdlůfjalsůkdjflůksd'.
    self assert: readData third = 'Longer_than_256_chars_max_long|arsdfasdfjljljasdf;jl;jljsfasdfasdfljaslkdfjkasdfljalsd;jfa;lsdjflkasjdflkajsdflkjasdflkjsadlfjasldfjlsadjflksdjflksadjflkajsdflkjasdlfjalskdjflkasdjflkasdfkj;sdaf;kljkkjkklkjjjjkas|1asdfjsldfjlasdlfjlasdjfljasdlfjalsdjflajdfsdsasdfa|endsdfsdfasdfasdfasdfjlkasdjflkasjdflkjasdlfjaslkdfjlkasdjflkasdflksadlkjsadlfalsdfůlasdjflkasdjflkasjdflkůjasdflůkjasdlůfjalsůkdjflůksd'.

    "  
     self run:#testReadvalueNamesAndValuesDo_MaxPath_01
     self new testReadvalueNamesAndValuesDo_MaxPath_01
    "

    "Created: / 22-11-2018 / 14:10:34 / svestkap"
    "Modified (format): / 01-02-2019 / 13:31:59 / svestkap"
!

testReadvalueNamesAndValuesDo_REG_SZ_02
    "Testing if REG_SZ values are read correctly via valueNamesAndValuesDo:"
    | readData testingRegistryPath |
    
    readData := OrderedDictionary new.    
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
     
    testingRegistryPath valueNamesAndValuesDo: [ :name :data |
        readData at: name put: data
    ].
    
    self assert: (readData at: ' ř ž č ル.          ') = 'Testing Unicode chars ř ž č ルすしかき'.    

    "
     self run:#testReadvalueNamesAndValuesDo_REG_SZ_02
     self new testReadvalueNamesAndValuesDo_REG_SZ_02
    "

    "Created: / 16-11-2018 / 12:16:16 / svestkap"
    "Modified (format): / 01-02-2019 / 13:32:02 / svestkap"
! !

!Win32OperatingSystemTest methodsFor:'tests-unicodeRename'!

testRenameSubKey_01
    "Testing if subKey is correctly renamed"
    | readData testingRegistryEntryPath |   

    testingRegistryEntryPath := Win32OperatingSystem registryEntry key: registryPath.
    
    self assert: (testingRegistryEntryPath renameSubKey: ' ルすしか_testing_delete'  to: 'RenamedSubKey').
    readData := testingRegistryEntryPath subKeyNamed: 'RenamedSubKey'.
    
    self assert: readData notEmptyOrNil.
    self assert: readData path = (registryPath, '\', 'RenamedSubKey').

    "
     self run:#testRenameSubKey_01
     self new testRenameSubKey_01
    "

    "Created: / 09-04-2019 / 09:05:28 / svestkap"
!

testRenameSubKey_02
    "Testing if subKey is correctly renamed"
    | readData testingRegistryEntryPath |   

    testingRegistryEntryPath := Win32OperatingSystem registryEntry key: registryPath.
    
    self assert: (testingRegistryEntryPath renameSubKey: ' ルすしか_testing_delete'  to: 'すしか_').
    readData := testingRegistryEntryPath subKeyNamed: 'すしか_'.
    
    self assert: readData notEmptyOrNil.
    self assert: readData path = (registryPath, '\', 'すしか_').

    testingRegistryEntryPath := Win32OperatingSystem registryEntry key: (registryPath, '\', 'すしか_').
    readData := testingRegistryEntryPath subKeyNamed: 'bobr'.
    
    self assert: readData notEmptyOrNil.
    self assert: readData path = (registryPath, '\', 'すしか_', '\', 'bobr')
    
    "
     self run:#testRenameSubKey_02
     self new testRenameSubKey_02
    "

    "Created: / 09-04-2019 / 09:35:05 / svestkap"
!

testRenameSubKey_03
    "Testing when renamed subKey does not exist"
    | readData testingRegistryEntryPath |   

    testingRegistryEntryPath := Win32OperatingSystem registryEntry key: registryPath.
    
    self deny: (testingRegistryEntryPath renameSubKey: 'a key that does not exist'  to: 'すしか_').
    readData := testingRegistryEntryPath subKeyNamed: 'すしか_'.
    
    self assert: readData isEmptyOrNil
    
    "
     self run:#testRenameSubKey_03
     self new testRenameSubKey_03
    "

    "Created: / 09-04-2019 / 09:39:52 / svestkap"
! !

!Win32OperatingSystemTest methodsFor:'tests-unicodeWrite'!

testDefaultValue_01
    "Testing if value can be stored (defaultValue:) and read (defaultValue)
     Note: the value is stored in (Default) value at the key"
    | testingRegistryPath readData |
    
    registryPath := registryPath, '\', ' ルすしか'.
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    
    readData := testingRegistryPath defaultValue.
    self assert: readData isNil.
    
    testingRegistryPath defaultValue: 'すし.ACE.OLEDB.16.0'.    
    
    readData := testingRegistryPath defaultValue.
    self assert: readData = 'すし.ACE.OLEDB.16.0'.
    
    "
     self run:#testDefaultValue_01
     self new testDefaultValue_01
    "

    "Created: / 12-12-2018 / 12:35:53 / svestkap"
    "Modified (format): / 01-02-2019 / 13:55:01 / svestkap"
!

testDefaultValue_02
    "Testing if value can be stored (defaultValue:) and read (defaultValue) with registry type and size check
     Note: the value is stored in (Default) value at the key"
    | testingRegistryPath registryType readData |

    registryPath := registryPath, '\', ' ルすしか'.
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
  
    readData := testingRegistryPath defaultValue.
    self assert: readData isNil.       
    
    testingRegistryPath defaultValue: 'すし.ACE.OLEDB.16.0'.    
    
    registryType := testingRegistryPath valueTypeAndSize: ''.
    self assert: registryType keys first isSymbol.
    self assert: registryType keys first equals: #REG_SZ.
    self assert: registryType first isNumber.
    self assert: registryType first equals: 17.     
    
    
    readData := testingRegistryPath defaultValue.
    
    self assert: readData = 'すし.ACE.OLEDB.16.0'.
    
    "
     self run:#testDefaultValue_02
     self new testDefaultValue_02
    "

    "Created: / 12-12-2018 / 11:07:11 / svestkap"
    "Modified: / 12-12-2018 / 14:08:14 / svestkap"
    "Modified (comment): / 01-02-2019 / 13:55:06 / svestkap"
!

testWriteValueNamedPut_REG_BINARY_01
    "Testing if REG_BINARY zero value is written correctly via valueNamed:put:
     Data is written and read back again." 
    | testingRegistryPath readData |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.    
    testingRegistryPath valueNamed: 'non-zero' put: ByteArray new.
    
    readData := testingRegistryPath valueNamed: 'non-zero'.    
    
    self assert: readData = ByteArray new.
    
    "
     self run:#testWriteValueNamedPut_REG_BINARY_01
     self new testWriteValueNamedPut_REG_BINARY_01
    "

    "Created: / 04-12-2018 / 11:52:46 / svestkap"
    "Modified (format): / 01-02-2019 / 13:55:10 / svestkap"
!

testWriteValueNamedPut_REG_BINARY_02
    "Testing if REG_BINARY values are written correctly via valueNamed:put:
     Data is written and read back again." 
    | testingRegistryPath byteArray readData readDataHex |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    
    byteArray := ByteArray new: 5.
    "/ data to be written  
    byteArray replaceElementsFrom: 1 to: 5 withArray: #[18 234 11 0 18] startingAt: 1. 
    
    testingRegistryPath valueNamed: 'non-zero' put: byteArray.
    
    readData := testingRegistryPath valueNamed: 'non-zero'.
    readDataHex := readData hexPrintStringWithSeparator: $|.
    
    self assert: readData = #[18 234 11 0 18]. "/ ByteArray
    self assert: readDataHex = '12|EA|0B|00|12' "/ hex    

    "
     self run:#testWriteValueNamedPut_REG_BINARY_02
     self new testWriteValueNamedPut_REG_BINARY_02
    "

    "Created: / 04-12-2018 / 12:04:18 / svestkap"
    "Modified (format): / 01-02-2019 / 13:55:13 / svestkap"
!

testWriteValueNamedPut_REG_BINARY_03
    "Testing if new REG_BINARY value name is written correctly via valueNamed:put:
     Data is written and read back again." 
    | testingRegistryPath byteArray readData readDataHex |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    
    byteArray := ByteArray new: 5.
    "/ data to be written  
    byteArray replaceElementsFrom: 1 to: 5 withArray: #[18 234 11 0 18] startingAt: 1. 
    
    testingRegistryPath valueNamed: 'Binaryル' put: byteArray.
    
    readData := testingRegistryPath valueNamed: 'Binaryル'.
    readDataHex := readData hexPrintStringWithSeparator: $|.
    
    self assert: readData = #[18 234 11 0 18]. "/ ByteArray
    self assert: readDataHex = '12|EA|0B|00|12' "/ hex    

    "
     self run:#testWriteValueNamedPut_REG_BINARY_03
     self new testWriteValueNamedPut_REG_BINARY_03
    "

    "Created: / 07-12-2018 / 15:15:06 / svestkap"
    "Modified (format): / 01-02-2019 / 13:56:49 / svestkap"
!

testWriteValueNamedPut_REG_BINARY_04
    "Testing if new REG_BINARY value name is written correctly via valueNamed:put: with registry type and size check
     Data is written and read back again." 
    | testingRegistryPath byteArray readData readDataHex registryType |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
       
    byteArray := ByteArray new: 5.
    "/ data to be written  
    byteArray replaceElementsFrom: 1 to: 5 withArray: #[18 234 11 0 18] startingAt: 1. 
    
    testingRegistryPath valueNamed: 'Binaryル' put: byteArray.
    
    registryType := testingRegistryPath valueTypeAndSize: 'Binaryル'.
    self assert: registryType keys first equals: #REG_BINARY.
    self assert: registryType first equals: 5.   
    
    readData := testingRegistryPath valueNamed: 'Binaryル'.
    readDataHex := readData hexPrintStringWithSeparator: $|.
    
    self assert: readData = #[18 234 11 0 18]. "/ ByteArray
    self assert: readDataHex = '12|EA|0B|00|12' "/ hex    

    "
     self run:#testWriteValueNamedPut_REG_BINARY_04
     self new testWriteValueNamedPut_REG_BINARY_04
    "

    "Created: / 12-12-2018 / 12:36:46 / svestkap"
    "Modified (format): / 01-02-2019 / 13:56:52 / svestkap"
!

testWriteValueNamedPut_REG_BINARY_05
    "Testing if REG_BINARY values are written correctly via valueNamed:put:
     Data is written and read back again." 
    | testingRegistryPath byteArray readData readDataHex registryType |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    
    readData := testingRegistryPath valueNamed: 'non-zero'.
    self assert: readData = #[17 16].
    registryType := testingRegistryPath valueTypeAndSize: 'non-zero'.
    self assert: registryType keys first equals: #REG_BINARY.
    self assert: registryType first equals: 2.              
    
    byteArray := ByteArray new: 5.
    "/ data to be written  
    byteArray replaceElementsFrom: 1 to: 5 withArray: #[18 234 11 0 18] startingAt: 1. 
    "/ saving value into registry
    testingRegistryPath valueNamed: 'non-zero' put: byteArray.
    
    "/ testing the saved value
    registryType := testingRegistryPath valueTypeAndSize: 'non-zero'.
    self assert: registryType keys first equals: #REG_BINARY.
    self assert: registryType first equals: 5.
    
    readData := testingRegistryPath valueNamed: 'non-zero'.
    readDataHex := readData hexPrintStringWithSeparator: $|.
    
    self assert: readData = #[18 234 11 0 18]. "/ ByteArray
    self assert: readDataHex = '12|EA|0B|00|12' "/ hex    

    "
     self run:#testWriteValueNamedPut_REG_BINARY_05
     self new testWriteValueNamedPut_REG_BINARY_05
    "

    "Created: / 12-12-2018 / 13:16:13 / svestkap"
    "Modified (format): / 01-02-2019 / 13:56:55 / svestkap"
!

testWriteValueNamedPut_REG_DWORD_01
    "Testing if REG_DWORD values are written correctly via valueNamed:put:"
    | readData testingRegistryPath |
  
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: 'dword_value' put: 7337.
    readData := testingRegistryPath valueNamed: 'dword_value'.

    self assert: readData = 7337.

    "
     self run:#testWriteValueNamedPut_REG_DWORD_01
     self new testWriteValueNamedPut_REG_DWORD_01
    "

    "Created: / 05-12-2018 / 11:35:52 / svestkap"
    "Modified: / 12-02-2019 / 14:54:58 / svestkap"
!

testWriteValueNamedPut_REG_DWORD_02
    "Testing if max DWORD is accepted as REG_DWORD (written correctly via valueNamed:put:)"
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    "/ max DWORD value 0xffffffff -> 4294967295 (which is on x64 SmallInteger)    
    testingRegistryPath valueNamed: 'dword_value' put: 4294967295.
    readData := testingRegistryPath valueNamed: 'dword_value'.

    self assert: readData = 4294967295.

    "
     self run:#testWriteValueNamedPut_REG_DWORD_02
     self new testWriteValueNamedPut_REG_DWORD_02
    "

    "Created: / 05-12-2018 / 11:36:00 / svestkap"
    "Modified: / 12-02-2019 / 14:55:03 / svestkap"
!

testWriteValueNamedPut_REG_DWORD_03
    "Testing if REG_DWORD values are written correctly via valueNamed:put:
     Data is written and read back again."
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: '11' put: 7337.
    readData := testingRegistryPath valueNamed: '11'.

    self assert: readData = 7337

    "
     self run:#testWriteValueNamedPut_REG_DWORD_03
     self new testWriteValueNamedPut_REG_DWORD_03
    "

    "Created: / 05-12-2018 / 11:35:36 / svestkap"
    "Modified: / 12-02-2019 / 14:55:08 / svestkap"
!

testWriteValueNamedPut_REG_DWORD_04
    "Testing if REG_DWORD values are written correctly via valueNamed:put:
     Data is written and read back again."
    | readData testingRegistryPath |
       
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: '11' put: 7337.
    readData := testingRegistryPath valueNamed: '11'.

    self assert: readData = 7337

    "
     self run:#testWriteValueNamedPut_REG_DWORD_04
     self new testWriteValueNamedPut_REG_DWORD_04
    "

    "Created: / 05-12-2018 / 11:39:00 / svestkap"
    "Modified: / 12-02-2019 / 14:55:14 / svestkap"
!

testWriteValueNamedPut_REG_DWORD_05
    "Testing if trying to access REG_DWORD values via name as number raises a predefined error"
    | testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.

    self should: [ testingRegistryPath valueNamed: 11 put: 7337] raise: Error
        suchThat: [ :e | e messageText = 'nameString is not a string!!' ].        

    "
     self run:#testWriteValueNamedPut_REG_DWORD_05
     self new testWriteValueNamedPut_REG_DWORD_05
    "

    "Created: / 05-12-2018 / 12:29:06 / svestkap"
    "Modified (comment): / 01-02-2019 / 14:28:28 / svestkap"
!

testWriteValueNamedPut_REG_DWORD_06
    "Testing if new REG_DWORD value name is written correctly via valueNamed:put:
     Data is written and read back again."

    | readData testingRegistryPath |
     
    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: '374657654ル' put: 7337.
    readData := testingRegistryPath valueNamed: '374657654ル'.

    self assert: readData = 7337

    "
     self run:#testWriteValueNamedPut_REG_DWORD_06
     self new testWriteValueNamedPut_REG_DWORD_06
    "

    "Created: / 07-12-2018 / 15:10:24 / svestkap"
    "Modified: / 12-02-2019 / 14:55:23 / svestkap"
!

testWriteValueNamedPut_REG_DWORD_07
    "Testing if REG_DWORD values are written correctly via valueNamed:put: with registry type and size check"
    | readData testingRegistryPath registryType endianness |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    
    "/ checking registry type and size
    registryType := testingRegistryPath valueTypeAndSize: 'dword_value'.
    registryType keys first == #REG_DWORD_LITTLE_ENDIAN ifTrue: [ 
        self assert: registryType keys first equals: #REG_DWORD_LITTLE_ENDIAN.
        endianness := #REG_DWORD_LITTLE_ENDIAN
    ] ifFalse: [ 
        self assert: registryType keys first equals: #REG_DWORD_BIG_ENDIAN.
        endianness := #REG_DWORD_BIG_ENDIAN
    ].  
    self assert: registryType first equals: 4. "/ 32 bits = 4 bytes      
    "/ read data
    readData := testingRegistryPath valueNamed: 'dword_value'.
    self assert: readData = 9135. "/ the previous value
    
    "/ inserting new value
    testingRegistryPath valueNamed: 'dword_value' put: 7337.  
    
    "/ checking registry type and size
    registryType := testingRegistryPath valueTypeAndSize: 'dword_value'.
    self assert: registryType keys first equals: endianness.
    self assert: registryType first equals: 4. "/ 32 bits = 4 bytes    
    
    "/ read data
    readData := testingRegistryPath valueNamed: 'dword_value'.    
    self assert: readData = 7337.

    "
     self run:#testWriteValueNamedPut_REG_DWORD_07
     self new testWriteValueNamedPut_REG_DWORD_07
    "

    "Created: / 12-12-2018 / 12:13:53 / svestkap"
    "Modified: / 12-02-2019 / 14:55:30 / svestkap"
!

testWriteValueNamedPut_REG_EXPAND_SZ_01
    "Testing if REG_EXPAND_SZ values are written correctly via valueNamed:put:
     Data is written and read back again."
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: 'bledesu' put: '"%PATH%"' unexpandedReferences: true.
    readData := testingRegistryPath valueNamed: 'bledesu'.
    
    self assert: readData = '"%PATH%"'

    "
     self run:#testWriteValueNamedPut_REG_EXPAND_SZ_01
     self new testWriteValueNamedPut_REG_EXPAND_SZ_01
    "

    "Created: / 07-12-2018 / 15:08:50 / svestkap"
    "Modified: / 12-02-2019 / 14:55:35 / svestkap"
!

testWriteValueNamedPut_REG_EXPAND_SZ_02
    "Testing if new REG_EXPAND_SZ value name is written correctly via valueNamed:put:
     Data is written and read back again."
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: 'Yooooル' put: '"%PATH%"' unexpandedReferences: true.
    readData := testingRegistryPath valueNamed:  'Yooooル'.
    
    self assert: readData = '"%PATH%"'

    "
     self run:#testWriteValueNamedPut_REG_EXPAND_SZ_02
     self new testWriteValueNamedPut_REG_EXPAND_SZ_02
    "

    "Created: / 07-12-2018 / 15:09:14 / svestkap"
    "Modified: / 12-02-2019 / 14:55:38 / svestkap"
!

testWriteValueNamedPut_REG_EXPAND_SZ_03
    "Testing if new REG_EXPAND_SZ value name is written correctly via valueNamed:put: with registry type and size check
     Data is written and read back again."
    | readData testingRegistryPath registryType |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: 'Yooooル' put: '"%PATH%"' unexpandedReferences: true.
    
    registryType := testingRegistryPath valueTypeAndSize: 'Yooooル'.
    self assert: registryType keys first equals: #REG_EXPAND_SZ.
    self assert: registryType first equals: 8.    
    
    readData := testingRegistryPath valueNamed:  'Yooooル'.
    self assert: readData = '"%PATH%"'

    "
     self run:#testWriteValueNamedPut_REG_EXPAND_SZ_03
     self new testWriteValueNamedPut_REG_EXPAND_SZ_03
    "

    "Created: / 12-12-2018 / 12:41:44 / svestkap"
    "Modified (format): / 12-02-2019 / 14:55:44 / svestkap"
!

testWriteValueNamedPut_REG_EXPAND_SZ_04
    "Testing if REG_EXPAND_SZ values are written correctly via valueNamed:put: with registry type and size check    
     Data is written and read back again (notice the registry type change #REG_SZ to #REG_EXPAND_SZ)."
    | readData testingRegistryPath registryType |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    "/ checking type and size
    registryType := testingRegistryPath valueTypeAndSize: 'bledesu'.
    self assert: registryType keys first equals: #REG_SZ.
    self assert: registryType first equals: 47.    
    "/ checking the actual value
    readData := testingRegistryPath valueNamed: 'bledesu'.                                                              
    self assert: readData = '''Testing Unicode chars ř ž č ルすしかき'').          '.
    
    "/ saving value into the registry
    testingRegistryPath valueNamed: 'bledesu' put: '"%PATH%"' unexpandedReferences: true.
    "/ checking type and size
    registryType := testingRegistryPath valueTypeAndSize: 'bledesu'.
    self assert: registryType keys first equals: #REG_EXPAND_SZ.
    self assert: registryType first equals: 8.        
    "/ checking the actual value 
    readData := testingRegistryPath valueNamed: 'bledesu'.
    self assert: readData = '"%PATH%"'

    "
     self run:#testWriteValueNamedPut_REG_EXPAND_SZ_04
     self new testWriteValueNamedPut_REG_EXPAND_SZ_04
    "

    "Created: / 12-12-2018 / 13:22:25 / svestkap"
    "Modified: / 12-02-2019 / 14:55:52 / svestkap"
!

testWriteValueNamedPut_REG_MULTI_SZ_01
    "Testing if REG_MULTI_SZ values are write correctly via valueNamed:put:"
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: 'Font_Leelawadee UI Bold' put: #('SEGOEUIB.TTF,Segoe UI Bold,110,82' 'řeřicha - ルすしかき').
    readData := testingRegistryPath valueNamed: 'Font_Leelawadee UI Bold'.

    self assert: readData = #('SEGOEUIB.TTF,Segoe UI Bold,110,82' 'řeřicha - ルすしかき').

    "
     self run:#testWriteValueNamedPut_REG_MULTI_SZ_01
     self new testWriteValueNamedPut_REG_MULTI_SZ_01
    "

    "Created: / 27-11-2018 / 09:29:57 / svestkap"
    "Modified (format): / 01-02-2019 / 14:30:32 / svestkap"
!

testWriteValueNamedPut_REG_MULTI_SZ_02
    "Testing if REG_MULTI_SZ values are write correctly via valueNamed:put:
     Note: The value data could be up to available memory on Windows 10 (in reality NOT recommended to go over 1MB).
     On older Windows (2003/XP) there was a hard limit on 1MB."
    | testingRegistryPath testData testDataArray readData |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.    
    testData := OrderedCollection new.
    
    "This is rather tricky to test.  It must test the functionality but on all windows.  Since older windows have a hard limit
     of 1MB (for ASCII).  Since Windows use UTF-16 internal you have to count 2 bytes per 1 character. There maybe a 4bytes per character,
     to be on the safe side, the 256kB limit will be used.  On Windows 10 the limit is much higher, perhaps all the available memory."    
    "/ 256kB (storing in worst case scenario / 48characters (unicode) -> 5333times        
    5333 timesRepeat: [ testData add: 'SEGOEUIB.TTF,Segoe UI Bold,110,82'.
                       testData add: 'řeřicha - ルすしかき'
    ].
    
    testDataArray := testData asArray.
    "/ storing the array        
    testingRegistryPath valueNamed: 'ř ž č ルすしか' put: testDataArray.
    "/ reading the stored array back
    readData := testingRegistryPath valueNamed: 'ř ž č ルすしか'.
        
    self assert: readData = testDataArray.
    
    "
     self run:#testWriteValueNamedPut_REG_MULTI_SZ_02
     self new testWriteValueNamedPut_REG_MULTI_SZ_02
    "

    "Created: / 28-11-2018 / 14:46:55 / svestkap"
    "Modified (comment): / 12-02-2019 / 15:08:08 / svestkap"
!

testWriteValueNamedPut_REG_MULTI_SZ_03
    "Testing if REG_MULTI_SZ an empty array is written via valueNamed:put:"
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: 'Font_Leelawadee UI Bold' put: Array new.
    readData := testingRegistryPath valueNamed: 'Font_Leelawadee UI Bold'.

    self assert: readData isEmpty.
    self assert: readData isArray.

    "
     self run:#testWriteValueNamedPut_REG_MULTI_SZ_03
     self new testWriteValueNamedPut_REG_MULTI_SZ_03
    "

    "Created: / 05-12-2018 / 11:54:05 / svestkap"
    "Modified (comment): / 01-02-2019 / 14:33:14 / svestkap"
!

testWriteValueNamedPut_REG_MULTI_SZ_04
    "Testing if new REG_MULTI_SZ value name is written correctly via valueNamed:put:"
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: 'new_reg_multiル' put: #('SEGOEUIB.TTF,Segoe UI Bold,110,82' 'řeřicha - ルすしかき').
    readData := testingRegistryPath valueNamed: 'new_reg_multiル'.

    self assert: readData = #('SEGOEUIB.TTF,Segoe UI Bold,110,82' 'řeřicha - ルすしかき').

    "
     self run:#testWriteValueNamedPut_REG_MULTI_SZ_04
     self new testWriteValueNamedPut_REG_MULTI_SZ_04
    "

    "Created: / 07-12-2018 / 15:08:03 / svestkap"
    "Modified (format): / 01-02-2019 / 14:33:54 / svestkap"
!

testWriteValueNamedPut_REG_MULTI_SZ_05
    "Testing if REG_MULTI_SZ values are write correctly via valueNamed:put: with registry type and size check"
    | registryType readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: 'Font_Leelawadee UI Bold' put: #('SEGOEUIB.TTF,Segoe UI Bold,110,82' 'řeřicha - ルすしかき').
    readData := testingRegistryPath valueNamed: 'Font_Leelawadee UI Bold'.

    self assert: readData = #('SEGOEUIB.TTF,Segoe UI Bold,110,82' 'řeřicha - ルすしかき').
    
    registryType := testingRegistryPath valueTypeAndSize: 'Font_Leelawadee UI Bold'.
    self assert: registryType keys first equals: #REG_MULTI_SZ.
    
    "/ (array node size + terminating null) + (array node size + terminating null) * sizeof(wchar_t) + terminating null
    "/ ((Array at: 1) size + 1) + ((Array at: 2) size + 1) * 2 + 1 = (34 + 16) * 2 + 1 = 101     
    self assert: (registryType at: #REG_MULTI_SZ) equals: 101.       
    "
     self run:#testWriteValueNamedPut_REG_MULTI_SZ_05
     self new testWriteValueNamedPut_REG_MULTI_SZ_05
    "

    "Created: / 12-12-2018 / 11:34:08 / svestkap"
    "Modified (format): / 01-02-2019 / 14:34:22 / svestkap"
!

testWriteValueNamedPut_REG_NONE_01
    "Testing if REG_NONE values are written correctly via valueNamed:put:
     Data is written and read back again."
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: 'bledesu' put: nil.
    readData := testingRegistryPath valueNamed: 'bledesu'.
    
    self assert: readData isNil

    "
     self run:#testWriteValueNamedPut_REG_NONE_01
     self new testWriteValueNamedPut_REG_NONE_01
    "

    "Created: / 07-12-2018 / 15:06:08 / svestkap"
    "Modified: / 12-02-2019 / 14:56:08 / svestkap"
!

testWriteValueNamedPut_REG_NONE_02
    "Testing if new REG_NONE value name is written correctly via valueNamed:put:
     Data is written and read back again."
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: 'New nilル name' put: nil.
    readData := testingRegistryPath valueNamed: 'New nilル name'.
    
    self assert: readData isNil

    "
     self run:#testWriteValueNamedPut_REG_NONE_02
     self new testWriteValueNamedPut_REG_NONE_02
    "

    "Created: / 07-12-2018 / 15:06:48 / svestkap"
    "Modified: / 12-02-2019 / 14:56:13 / svestkap"
!

testWriteValueNamedPut_REG_NONE_03
    "Testing if new REG_NONE value name is written correctly via valueNamed:put: 
     with registry type and size check. Data is written and read back again."
    | readData testingRegistryPath registryType |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: 'New nilル name' put: nil.
    
    registryType := testingRegistryPath valueTypeAndSize: 'New nilル name'.
    self assert: registryType keys first equals: #REG_NONE.
    self assert: registryType first equals: 0.    
    
    readData := testingRegistryPath valueNamed: 'New nilル name'.
    
    self assert: readData isNil

    "
     self run:#testWriteValueNamedPut_REG_NONE_03
     self new testWriteValueNamedPut_REG_NONE_03
    "

    "Created: / 12-12-2018 / 12:47:40 / svestkap"
    "Modified: / 12-02-2019 / 14:56:19 / svestkap"
!

testWriteValueNamedPut_REG_QWORD_01
    "Testing if max QWORD value is written and read correctly from REG_QWORD (valueNamed:put: and valueNamed:).
     Storing maximum QWORD value (0xffffffffffffffff -> 18446744073709551615x64)"
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: 'qword_max' put: 18446744073709551615.
    readData := testingRegistryPath valueNamed: 'qword_max'.

    self assert: readData = 18446744073709551615.

    "
     self run:#testReadValueNamed_REG_QWORD_01
     self new testReadValueNamed_REG_QWORD_01
    "

    "Created: / 26-11-2018 / 14:54:45 / svestkap"
    "Modified: / 07-12-2018 / 15:11:56 / svestkap"
    "Modified (comment): / 01-02-2019 / 14:37:55 / svestkap"
!

testWriteValueNamedPut_REG_QWORD_02
    "Testing what happens if more then max value is stored in REG_QWORD registry type (valueNamed:put: and valueNamed:)"
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    "/ max QWORD value is: 0xff-ff-ff-ff-ff-ff-ff-ff -> 18446744073709551615 (on x64 only)
    testingRegistryPath valueNamed: 'qword_max' put: 18446744073709551700.
    readData := testingRegistryPath valueNamed: 'qword_max'.

    self assert: readData ~= 18446744073709551700.
    "/ when you try to store more than maximum value you will get only the maximum losing the rest
    self assert: readData = 18446744073709551615.

    "
     self run:#testWriteValueNamedPut_REG_QWORD_02
     self new testWriteValueNamedPut_REG_QWORD_02
    "

    "Created: / 04-12-2018 / 11:02:20 / svestkap"
    "Modified: / 07-12-2018 / 15:12:12 / svestkap"
    "Modified (format): / 01-02-2019 / 14:36:06 / svestkap"
!

testWriteValueNamedPut_REG_QWORD_03
    "Testing if new QWORD value name is written and read correctly from REG_QWORD (valueNamed:put: and valueNamed:)"
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: 'qword_new_testingル' put: 18446744073709551101.
    readData := testingRegistryPath valueNamed: 'qword_new_testingル'.

    self assert: readData = 18446744073709551101.

    "
     self run:#testWriteValueNamedPut_REG_QWORD_03
     self new testWriteValueNamedPut_REG_QWORD_03
    "

    "Created: / 07-12-2018 / 15:05:48 / svestkap"
    "Modified: / 12-02-2019 / 14:56:27 / svestkap"
!

testWriteValueNamedPut_REG_QWORD_04
    "Testing if max QWORD value is written and read correctly from REG_QWORD (valueNamed:put: and valueNamed:)
     with registry type and size check. Storing maximum QWORD value (0xffffffffffffffff -> 18446744073709551615(x64))"
    | readData testingRegistryPath registryType |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: 'qword_max' put: 18446744073709551615.
    readData := testingRegistryPath valueNamed: 'qword_max'.
    
    registryType := testingRegistryPath valueTypeAndSize: 'qword_max'.
    self assert: registryType keys first equals: #REG_QWORD.
    self assert: registryType first equals: 8. "/ 64 bits = 8 bytes
    
    self assert: readData = 18446744073709551615.

    "
     self run:#testWriteValueNamedPut_REG_QWORD_04
     self new testWriteValueNamedPut_REG_QWORD_04
    "

    "Created: / 12-12-2018 / 12:08:35 / svestkap"
    "Modified (comment): / 01-02-2019 / 14:36:34 / svestkap"
!

testWriteValueNamedPut_REG_QWORD_05
    "Testing if max QWORD value is written and read correctly from REG_QWORD (valueNamed:put: and valueNamed:)
     with registry type and size check.  Notice the #REG_SZ -> #REG_QWORD change.
     Storing maximum QWORD value (0xffffffffffffffff -> 18446744073709551615(x64))"
    | readData testingRegistryPath registryType |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    "/ checking type and size
    registryType := testingRegistryPath valueTypeAndSize: ' ř ž č ル.          '.    
    self assert: registryType keys first equals: #REG_SZ.
    self assert: registryType first equals: 33. "/ string size
    "/ checking the value
    readData := testingRegistryPath valueNamed: ' ř ž č ル.          '.    
    self assert: readData = 'Testing Unicode chars ř ž č ルすしかき'.
    
    "/ saving into registry
    testingRegistryPath valueNamed: ' ř ž č ル.          ' put: 18446744073709551615.
        
    registryType := testingRegistryPath valueTypeAndSize: ' ř ž č ル.          '.    
    self assert: registryType keys first equals: #REG_QWORD.
    self assert: registryType first equals: 8. "/ 64 bits = 8 bytes
    
    readData := testingRegistryPath valueNamed: ' ř ž č ル.          '.    
    self assert: readData = 18446744073709551615.

    "
     self run:#testWriteValueNamedPut_REG_QWORD_05
     self new testWriteValueNamedPut_REG_QWORD_05
    "

    "Created: / 12-12-2018 / 13:38:31 / svestkap"
    "Modified (comment): / 01-02-2019 / 14:37:40 / svestkap"
!

testWriteValueNamedPut_REG_SZ_01
    "Testing if REG_SZ values are written correctly via valueNamed:put:.
     Data is written and read back again."
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: 'bledesu' put: 'řeřicha - ルすしかき'.
    readData := testingRegistryPath valueNamed: 'bledesu'.
    
    self assert: readData = 'řeřicha - ルすしかき'.

    "
     self run:#testWriteValueNamedPut_REG_SZ_01
     self new testWriteValueNamedPut_REG_SZ_01
    "

    "Created: / 26-11-2018 / 09:51:58 / svestkap"
    "Modified: / 12-02-2019 / 14:56:40 / svestkap"
!

testWriteValueNamedPut_REG_SZ_02
    "Testing if REG_SZ values are written correctly via valueNamed:put:. Data is written and read back again.
     Note: this is testing Unicode with spaces - probably the worst combination"
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: 'しかき    ' put: 'řeřicha - ルすしかき'.
    readData := testingRegistryPath valueNamed: 'しかき    '.

    self assert: readData = 'řeřicha - ルすしかき'.

    "
     self run:#testReadValueNamed_REG_SZ_03
     self new testReadValueNamed_REG_SZ_03
    "

    "Created: / 26-11-2018 / 14:10:35 / svestkap"
    "Modified: / 12-02-2019 / 14:56:44 / svestkap"
!

testWriteValueNamedPut_REG_SZ_03
    "Testing if REG_SZ empty value is written correctly via valueNamed:put:. Data is written and read back again.
     Note: this is testing Unicode with spaces - probably the worst combination"
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: 'しかき    ' put: ''.
    readData := testingRegistryPath valueNamed: 'しかき    '.

    self assert: readData = ''

    "
     self run:#testWriteValueNamedPut_REG_SZ_03
     self new testWriteValueNamedPut_REG_SZ_03
    "

    "Created: / 05-12-2018 / 10:16:59 / svestkap"
    "Modified: / 12-02-2019 / 14:56:47 / svestkap"
!

testWriteValueNamedPut_REG_SZ_04
    "Testing if REG_SZ empty value is written correctly via valueNamed:put:. Data is written and read back again.
     Note: this is testing Unicode with spaces - probably the worst combination"
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: 'bledesu' put: ''.
    readData := testingRegistryPath valueNamed: 'bledesu'.

    self assert: readData = ''

    "
     self run:#testWriteValueNamedPut_REG_SZ_04
     self new testWriteValueNamedPut_REG_SZ_04
    "

    "Created: / 05-12-2018 / 10:22:39 / svestkap"
    "Modified: / 12-02-2019 / 14:56:51 / svestkap"
!

testWriteValueNamedPut_REG_SZ_05
    "Testing if REG_SZ completely new value is written correctly via valueNamed:put:.
     Data is written and read back again."
    | readData testingRegistryPath |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: 'Newル guy' put: 'Singルing'.
    readData := testingRegistryPath valueNamed: 'Newル guy'.

    self assert: readData = 'Singルing'

    "
     self run:#testWriteValueNamedPut_REG_SZ_05
     self new testWriteValueNamedPut_REG_SZ_05
    "

    "Created: / 07-12-2018 / 15:03:05 / svestkap"
    "Modified: / 12-02-2019 / 14:56:54 / svestkap"
!

testWriteValueNamedPut_REG_SZ_06
    "Testing if REG_SZ completely new value is written correctly via valueNamed:put: with registry type and size check
     Data is written and read back again."
    | readData testingRegistryPath registryType |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    testingRegistryPath valueNamed: 'Newル guy' put: 'Singルing'.
    
    registryType := testingRegistryPath valueTypeAndSize: 'Newル guy'.
    self assert: registryType keys first equals: #REG_SZ.
    self assert: registryType first equals: 8.           
   
    readData := testingRegistryPath valueNamed: 'Newル guy'. 
    self assert: readData = 'Singルing'

    "
     self run:#testWriteValueNamedPut_REG_SZ_06
     self new testWriteValueNamedPut_REG_SZ_06
    "

    "Created: / 12-12-2018 / 12:39:52 / svestkap"
    "Modified: / 12-02-2019 / 14:56:58 / svestkap"
!

testWriteValueNamedPut_REG_SZ_07
    "Testing if REG_SZ values are written correctly via valueNamed:put:. Data is written and read back again.
     Note: the registry type change: #REG_MULTI_SZ to #REG_SZ."
    | readData testingRegistryPath registryType |

    testingRegistryPath := Win32OperatingSystem registryEntry key: registryPath.
    "/ reading type and size
    registryType := testingRegistryPath valueTypeAndSize: 'ř ž č ルすしか'.
    self assert: registryType keys first equals: #REG_MULTI_SZ.
    self assert: registryType first equals: 974. "/ REG_MULTI_SZ size in bytes
   
    "/ saving data (unicode string) into registry
    testingRegistryPath valueNamed: 'bledesu' put: 'řeřicha - ルすしかき'.
    
    registryType := testingRegistryPath valueTypeAndSize: 'bledesu'.
    self assert: registryType keys first equals: #REG_SZ.
    self assert: registryType first equals: 15.              
    
    readData := testingRegistryPath valueNamed: 'bledesu'.
    self assert: readData = 'řeřicha - ルすしかき'.

    "
     self run:#testWriteValueNamedPut_REG_SZ_07
     self new testWriteValueNamedPut_REG_SZ_07
    "

    "Created: / 12-12-2018 / 13:48:00 / svestkap"
    "Modified: / 12-02-2019 / 14:57:02 / svestkap"
! !

!Win32OperatingSystemTest class methodsFor:'documentation'!

version
    ^ '$Header$'
!

version_HG

    ^ '$Changeset: <not expanded> $'
! !