Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 125 additions & 1 deletion atest/jsonpreprocessor/test_jsonpreprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,128 @@ def test_none_true_false_datatype(self):
assert oJsonData['convert_true_to_string'] == '"True"'
assert oJsonData['convert_false_to_string'] == '"False"'
assert oJsonData['params']['global'] == JSONFORMAT_NONE_TRUE_FALSE['params']['global']
assert oJsonData['preprocessor']['definitions'] == JSONFORMAT_NONE_TRUE_FALSE['preprocessor']['definitions']
assert oJsonData['preprocessor']['definitions'] == JSONFORMAT_NONE_TRUE_FALSE['preprocessor']['definitions']

class TestUTF8Encoding:

def test_utf8_encoding(self):
'''
Test utf-8 encoding
'''
sJsonfile = os.path.abspath("../testdata/config/08_utf8_encoding/utf8_format.json")
oJsonPreprocessor = CJsonPreprocessor(syntax="python")
oJsonData = oJsonPreprocessor.jsonLoad(sJsonfile)
assert oJsonData['German'] == "Dies ist der UTF-8 SälfTest"
assert oJsonData['Vietnamese'] == "Đây là bản tự kiểm tra UTF-8"
assert oJsonData['Japanese'] == "これは UTF-8 セルフテストです"
assert oJsonData['Hindi'] == "यह UTF-8 सेल्फ़टेस्ट है"
assert oJsonData['Thai'] == "นี่คือการทดสอบตัวเอง UTF-8"
assert oJsonData['Korean'] == "이것은 UTF-8 자체 테스트입니다"
assert oJsonData['Chinese'] == "這是 UTF-8 自測"

def test_utf8_encoding_both_key_and_value(self):
'''
Test utf-8 encoding in both key and value in json configuration file.
'''
sJsonfile = os.path.abspath("../testdata/config/08_utf8_encoding/utf8_format_02.json")
oJsonPreprocessor = CJsonPreprocessor(syntax="python")
oJsonData = oJsonPreprocessor.jsonLoad(sJsonfile)
assert oJsonData['Tiếng Đức'] == "Dies ist der UTF-8 SälfTest"
assert oJsonData['Tiếng Việt'] == "Đây là bản tự kiểm tra UTF-8"
assert oJsonData['日本'] == "これは UTF-8 セルフテストです"
assert oJsonData['हिंदी'] == "यह UTF-8 सेल्फ़टेस्ट है"
assert oJsonData['แบบไทย'] == "นี่คือการทดสอบตัวเอง UTF-8"
assert oJsonData['한국인'] == "이것은 UTF-8 자체 테스트입니다"
assert oJsonData['中國人'] == "這是 UTF-8 自測"

def test_utf8_encoding_imported_01(self):
'''
Test utf-8 encoding file is imported to other normal json config file
'''
sJsonfile = os.path.abspath("../testdata/config/02_import_json/import_file_utf8_format_01.json")
oJsonPreprocessor = CJsonPreprocessor(syntax="python")
oJsonData = oJsonPreprocessor.jsonLoad(sJsonfile)
assert oJsonData['German'] == "Dies ist der UTF-8 SälfTest"
assert oJsonData['Vietnamese'] == "Đây là bản tự kiểm tra UTF-8"
assert oJsonData['Japanese'] == "これは UTF-8 セルフテストです"
assert oJsonData['Hindi'] == "यह UTF-8 सेल्फ़टेस्ट है"
assert oJsonData['Thai'] == "นี่คือการทดสอบตัวเอง UTF-8"
assert oJsonData['Korean'] == "이것은 UTF-8 자체 테스트입니다"
assert oJsonData['Chinese'] == "這是 UTF-8 自測"

def test_utf8_encoding_imported_02(self):
'''
Test utf-8 encoding file is imported to other utf8 json config file
'''
sJsonfile = os.path.abspath("../testdata/config/02_import_json/import_file_utf8_format_02.json")
oJsonPreprocessor = CJsonPreprocessor(syntax="python")
oJsonData = oJsonPreprocessor.jsonLoad(sJsonfile)
assert oJsonData['German'] == "Dies ist der UTF-8 SälfTest"
assert oJsonData['Vietnamese'] == "Đây là bản tự kiểm tra UTF-8"
assert oJsonData['Japanese'] == "これは UTF-8 セルフテストです"
assert oJsonData['Hindi'] == "यह UTF-8 सेल्फ़टेस्ट है"
assert oJsonData['Thai'] == "นี่คือการทดสอบตัวเอง UTF-8"
assert oJsonData['Korean'] == "이것은 UTF-8 자체 테스트입니다"
assert oJsonData['Chinese'] == "這是 UTF-8 自測"

def test_utf8_encoding_imported_03(self):
'''
Test utf-8 encoding file is imported and overried by utf8 values to other json config file
'''
sJsonfile = os.path.abspath("../testdata/config/02_import_json/import_file_utf8_format_03.json")
oJsonPreprocessor = CJsonPreprocessor(syntax="python")
oJsonData = oJsonPreprocessor.jsonLoad(sJsonfile)
assert oJsonData['German'] == "Dies ist der UTF-8 SälfTest"
assert oJsonData['Vietnamese'] == "Đây là bản tự kiểm tra UTF-8"
assert oJsonData['Japanese'] == "これは UTF-8 セルフテストです"
assert oJsonData['Hindi'] == "यह UTF-8 सेल्फ़टेस्ट है"
assert oJsonData['Thai'] == "นี่คือการทดสอบตัวเอง UTF-8"
assert oJsonData['Korean'] == "이것은 UTF-8 자체 테스트입니다"
assert oJsonData['Chinese'] == "這是 UTF-8 自測"

def test_utf8_encoding_imported_04(self):
'''
Test utf-8 encoding - Override utf8 data by normal data
'''
sJsonfile = os.path.abspath("../testdata/config/02_import_json/import_file_utf8_format_04.json")
oJsonPreprocessor = CJsonPreprocessor(syntax="python")
oJsonData = oJsonPreprocessor.jsonLoad(sJsonfile)
assert oJsonData['German'] == "This is German"
assert oJsonData['Vietnamese'] == 84
assert oJsonData['Japanese'] == "Đây là tiếng Nhật"
assert oJsonData['Hindi'] == True
assert oJsonData['Thai'] == False
assert oJsonData['Korean'] == [1, 2, "List", 4, 5]
assert oJsonData['Chinese'] == None

def test_utf8_encoding_imported_05(self):
'''
Test utf-8 encoding - import normal json configuration file into utf8 file.
'''
sJsonfile = os.path.abspath("../testdata/config/08_utf8_encoding/utf8_format_01.json")
oJsonPreprocessor = CJsonPreprocessor(syntax="python")
oJsonData = oJsonPreprocessor.jsonLoad(sJsonfile)
assert oJsonData['German'] == "Dies ist der UTF-8 SälfTest"
assert oJsonData['Vietnamese'] == "Đây là bản tự kiểm tra UTF-8"
assert oJsonData['Japanese'] == "これは UTF-8 セルフテストです"
assert oJsonData['Hindi'] == "यह UTF-8 सेल्फ़टेस्ट है"
assert oJsonData['Thai'] == "นี่คือการทดสอบตัวเอง UTF-8"
assert oJsonData['Korean'] == "이것은 UTF-8 자체 테스트입니다"
assert oJsonData['Chinese'] == "這是 UTF-8 自測"
assert oJsonData['gPreprolIntParam'] == 1
assert oJsonData['gPreproFloatParam'] == 1.332
assert oJsonData['gPreproString'] == "This is a string"
assert oJsonData['gPreproStructure']['general'] == "general"

def test_utf8_encoding_imported_06(self):
'''
Test utf-8 encoding - Override parameters have utf8 format in keys.
'''
sJsonfile = os.path.abspath("../testdata/config/08_utf8_encoding/utf8_format_03.json")
oJsonPreprocessor = CJsonPreprocessor(syntax="python")
oJsonData = oJsonPreprocessor.jsonLoad(sJsonfile)
assert oJsonData['utf8']['Tiếng Đức'] == "This is German"
assert oJsonData['utf8']['Tiếng Việt'] == 84
assert oJsonData['utf8']['日本'] == 1.987
assert oJsonData['utf8']['हिंदी'] == "นี่คือการทดสอบตัวเอง UTF-8"
assert oJsonData['utf8']['한국인'] == "1"
2 changes: 1 addition & 1 deletion atest/run.bat
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@ECHO OFF
set current_dir=%CD%
cd %~dp0\jsonpreprocessor
"%RobotPythonPath%"\python -m pytest jsonpreprocessor_unittest.py --junit-xml=..\logs\windows_jsonpreprocessor_unittest.xml && (
"%RobotPythonPath%"\python -m pytest test_jsonpreprocessor.py --junit-xml=..\logs\windows_test_jsonpreprocessor.xml && (
echo Run JsonPreprocessor acceptance test sussessful!
) || (
echo Run JsonPreprocessor acceptance test failed!
Expand Down
2 changes: 1 addition & 1 deletion atest/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ atest_dir=`dirname $bash_file_path`
cd $atest_dir/jsonpreprocessor
export PYTHONPATH="$atest_dir/../"
echo $PYTHONPATH
$RobotPythonPath/python3 -m pytest jsonpreprocessor_unittest.py --junit-xml=../logs/linux_jsonpreprocessor_unittest.xml && (
$RobotPythonPath/python3 -m pytest test_jsonpreprocessor.py --junit-xml=../logs/linux_test_jsonpreprocessor.xml && (
echo "Run JsonPreprocessor acceptance test successful!"
) || (
echo "Run JsonPreprocessor acceptance test failed!"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2020-2022 Robert Bosch Car Multimedia GmbH
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************

{
"Project": "JsonPreprocessor",
"WelcomeString": "Hello... JsonPreprocessor selftest is running now!",
"[import]": "../import/utf8_format_data.json",
// Version control information.
"version": {
"majorversion": "0",
"minorversion": "1",
"patchversion": "1"
},
"TargetName" : "Device@01"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2020-2022 Robert Bosch Car Multimedia GmbH
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************

{
"Project": "JsonPreprocessor",
"WelcomeString": "Hello... JsonPreprocessor selftest is running now!",
"German": "Dies ist der UTF-8 SälfTest",
"Vietnamese": "Đây là bản tự kiểm tra UTF-8",
"Japanese": "これは UTF-8 セルフテストです",
"[import]": "../import/utf8_format_data_01.json",
// Version control information.
"version": {
"majorversion": "0",
"minorversion": "1",
"patchversion": "1"
},
"TargetName" : "Device@01"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2020-2022 Robert Bosch Car Multimedia GmbH
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************

{
"Project": "JsonPreprocessor",
"WelcomeString": "Hello... JsonPreprocessor selftest is running now!",
"German": "Will be overridden by German",
"Vietnamese": "Sẽ được ghi đè bằng câu tiếng Việt khác",
"Japanese": "Будет переопределен японским",
"[import]": "../import/utf8_format_data.json",
// Version control information.
"version": {
"majorversion": "0",
"minorversion": "1",
"patchversion": "1"
},
"TargetName" : "Device@01"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2020-2022 Robert Bosch Car Multimedia GmbH
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************

{
"Project": "JsonPreprocessor",
"German": "Dies ist der UTF-8 SälfTest",
"Vietnamese": "Đây là bản tự kiểm tra UTF-8",
"Japanese": "これは UTF-8 セルフテストです",
"Hindi": "यह UTF-8 सेल्फ़टेस्ट है",
"Thai": "นี่คือการทดสอบตัวเอง UTF-8",
"Korean": "이것은 UTF-8 자체 테스트입니다",
"Chinese": "這是 UTF-8 自測",
// Version control information.
"version": {
"majorversion": "0",
"minorversion": "1",
"patchversion": "1"
},
"TargetName" : "Device@01",
"[import]": "../import/utf8_format_data_02.json"
}
32 changes: 32 additions & 0 deletions atest/testdata/config/08_utf8_encoding/utf8_format.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2020-2022 Robert Bosch Car Multimedia GmbH
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************

{
"Project": "JsonPreprocessor",
"German": "Dies ist der UTF-8 SälfTest",
"Vietnamese": "Đây là bản tự kiểm tra UTF-8",
"Japanese": "これは UTF-8 セルフテストです",
"Hindi": "यह UTF-8 सेल्फ़टेस्ट है",
"Thai": "นี่คือการทดสอบตัวเอง UTF-8",
"Korean": "이것은 UTF-8 자체 테스트입니다",
"Chinese": "這是 UTF-8 自測",
// Version control information.
"version": {
"majorversion": "0",
"minorversion": "1",
"patchversion": "1"
},
"TargetName" : "Device@01"
}
33 changes: 33 additions & 0 deletions atest/testdata/config/08_utf8_encoding/utf8_format_01.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2020-2022 Robert Bosch Car Multimedia GmbH
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************

{
"Project": "JsonPreprocessor",
"German": "Dies ist der UTF-8 SälfTest",
"Vietnamese": "Đây là bản tự kiểm tra UTF-8",
"Japanese": "これは UTF-8 セルフテストです",
"Hindi": "यह UTF-8 सेल्फ़टेस्ट है",
"Thai": "นี่คือการทดสอบตัวเอง UTF-8",
"Korean": "이것은 UTF-8 자체 테스트입니다",
"Chinese": "這是 UTF-8 自測",
"[import]" : "../import/imported_file01_config.json",
// Version control information.
"version": {
"majorversion": "0",
"minorversion": "1",
"patchversion": "1"
},
"TargetName" : "Device@01"
}
32 changes: 32 additions & 0 deletions atest/testdata/config/08_utf8_encoding/utf8_format_02.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2020-2022 Robert Bosch Car Multimedia GmbH
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************

{
"Project": "JsonPreprocessor",
"Tiếng Đức": "Dies ist der UTF-8 SälfTest",
"Tiếng Việt": "Đây là bản tự kiểm tra UTF-8",
"日本": "これは UTF-8 セルフテストです",
"हिंदी": "यह UTF-8 सेल्फ़टेस्ट है",
"แบบไทย": "นี่คือการทดสอบตัวเอง UTF-8",
"한국인": "이것은 UTF-8 자체 테스트입니다",
"中國人": "這是 UTF-8 自測",
// Version control information.
"version": {
"majorversion": "0",
"minorversion": "1",
"patchversion": "1"
},
"TargetName" : "Device@01"
}
Loading