-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix can not parse 64-bits int from JSON (#1758)
The native side will return a 64-bits int ptr value, most of it is `view_t`, `void *`, which will cause the dart `jsonDecode` error, so we passed the int ptr value through the string, and parse it to the int value. This change is not yet supported on iris 4.3.x, so we do not apply any code changes at this time.
- Loading branch information
1 parent
d7415ab
commit d71cd95
Showing
3 changed files
with
184 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:agora_rtc_engine/src/impl/json_converters.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('readIntPtr', () { | ||
test('can parse int ptr from key pattern <key>_str', () async { | ||
const json = ''' | ||
{ | ||
"key": 18446744073709551615, | ||
"key_str": "18446744073709551615" | ||
} | ||
'''; | ||
final res = readIntPtr(jsonDecode(json), 'key'); | ||
// 18446744073709551615 is -1 in c++ | ||
expect(res, -1); | ||
}); | ||
|
||
test('can parse int ptr if no key pattern <key>_str', () async { | ||
const json = ''' | ||
{ | ||
"key": 18446744073709551615 | ||
} | ||
'''; | ||
final res = readIntPtr(jsonDecode(json), 'key'); | ||
// 18446744073709551615 become 18446744073709552000.0 after `jsonDecode` | ||
expect(res, 18446744073709552000.0); | ||
}); | ||
|
||
test( | ||
'throw assertion error if value of key pattern <key>_str is not type of String', | ||
() async { | ||
const json = ''' | ||
{ | ||
"key": 18446744073709551615, | ||
"key_str": 18446744073709551615 | ||
} | ||
'''; | ||
expect(() => readIntPtr(jsonDecode(json), 'key'), throwsAssertionError); | ||
}); | ||
}); | ||
|
||
group('readIntPtrList', () { | ||
test('can parse int ptr list from key pattern <key>_str', () async { | ||
const json = ''' | ||
{ | ||
"key": [18446744073709551615, 18446744073709551615], | ||
"key_str": ["18446744073709551615", "18446744073709551615"] | ||
} | ||
'''; | ||
final res = readIntPtrList(jsonDecode(json), 'key'); | ||
// 18446744073709551615 is -1 in c++ | ||
expect(res, const [-1, -1]); | ||
}); | ||
|
||
test('can parse int ptr list if no key pattern <key>_str', () async { | ||
const json = ''' | ||
{ | ||
"key": [18446744073709551615, 18446744073709551615] | ||
} | ||
'''; | ||
final res = readIntPtrList(jsonDecode(json), 'key'); | ||
// 18446744073709551615 become 18446744073709552000.0 after `jsonDecode` | ||
expect(res, [18446744073709552000.0, 18446744073709552000.0]); | ||
}); | ||
|
||
test( | ||
'throw assertion error if value of key pattern <key>_str is not type of List', | ||
() async { | ||
const json = ''' | ||
{ | ||
"key": [18446744073709551615, 18446744073709551615], | ||
"key_str": 18446744073709551615 | ||
} | ||
'''; | ||
expect( | ||
() => readIntPtrList(jsonDecode(json), 'key'), throwsAssertionError); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters