-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PAINTROID - Implement JSON Serialization via Code Generation
more tetsing
- Loading branch information
1 parent
7724d2b
commit bc991b2
Showing
6 changed files
with
159 additions
and
77 deletions.
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
36 changes: 0 additions & 36 deletions
36
lib/io/src/serialization/serializer/converter/path_action_converter.dart
This file was deleted.
Oops, something went wrong.
54 changes: 53 additions & 1 deletion
54
test/unit/io/serialization/commands/draw_path_command_serializer_test.dart
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 |
---|---|---|
@@ -1,8 +1,60 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:paintroid/command/command.dart'; | ||
import 'package:paintroid/core/path_with_action_history.dart'; | ||
|
||
void main() { | ||
|
||
test('Test...', () { | ||
Paint createPaint() { | ||
return Paint() | ||
..color = Colors.blue | ||
..strokeWidth = 5.0 | ||
..strokeCap = StrokeCap.round | ||
..isAntiAlias = true | ||
..style = PaintingStyle.fill | ||
..strokeJoin = StrokeJoin.bevel; | ||
} | ||
|
||
bool comparePaint(Paint paint1, Paint paint2) { | ||
return paint1.color == paint2.color && | ||
paint1.strokeWidth == paint2.strokeWidth && | ||
paint1.strokeCap == paint2.strokeCap && | ||
paint1.isAntiAlias == paint2.isAntiAlias && | ||
paint1.style == paint2.style && | ||
paint1.strokeJoin == paint2.strokeJoin; | ||
} | ||
|
||
PathWithActionHistory createPathWithActionHistory(int numberOfActions) { | ||
PathWithActionHistory pathWithActionHistory = PathWithActionHistory(); | ||
for (int i = 0; i < numberOfActions; i++) { | ||
pathWithActionHistory.moveTo(i.toDouble(), i.toDouble() + 1); | ||
pathWithActionHistory.lineTo(i.toDouble() + 2, i.toDouble() + 3); | ||
} | ||
pathWithActionHistory.close(); | ||
return pathWithActionHistory; | ||
} | ||
|
||
test('Test DrawPathCommand serialization with one path', () { | ||
PathWithActionHistory originalPath = createPathWithActionHistory(1); | ||
Paint originalPaint = createPaint(); | ||
DrawPathCommand command = DrawPathCommand(originalPath, originalPaint); | ||
|
||
var json = command.toJson(); | ||
DrawPathCommand deserializedCommand = DrawPathCommand.fromJson(json); | ||
|
||
expect(comparePaint(originalPaint, deserializedCommand.paint), isTrue); | ||
expect(originalPath, equals(deserializedCommand.path)); | ||
}); | ||
|
||
test('Test DrawPathCommand serialization with multiple paths', () { | ||
PathWithActionHistory originalPath = createPathWithActionHistory(5); | ||
Paint originalPaint = createPaint(); | ||
DrawPathCommand command = DrawPathCommand(originalPath, originalPaint); | ||
|
||
var json = command.toJson(); | ||
DrawPathCommand deserializedCommand = DrawPathCommand.fromJson(json); | ||
|
||
expect(comparePaint(originalPaint, deserializedCommand.paint), isTrue); | ||
expect(originalPath, equals(deserializedCommand.path)); | ||
}); | ||
} |
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
48 changes: 48 additions & 0 deletions
48
test/unit/io/serialization/converter/path_with_action_history_converter_test.dart
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,48 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:paintroid/core/path_with_action_history.dart'; | ||
import 'package:paintroid/io/src/json_serializer/converter/path_with_action_history_converter.dart'; | ||
|
||
void main() { | ||
|
||
const PathWithActionHistoryConverter converter = PathWithActionHistoryConverter(); | ||
|
||
PathWithActionHistory createPathWithActionHistory(int numberOfActions) { | ||
PathWithActionHistory pathWithActionHistory = PathWithActionHistory(); | ||
for (int i = 0; i < numberOfActions; i++) { | ||
pathWithActionHistory.moveTo(i.toDouble(), i.toDouble() + 1); | ||
pathWithActionHistory.lineTo(i.toDouble() + 2, i.toDouble() + 3); | ||
} | ||
pathWithActionHistory.close(); | ||
return pathWithActionHistory; | ||
} | ||
|
||
test('Test converter for PathWithActionHistory with one path', () { | ||
PathWithActionHistory path = createPathWithActionHistory(1); | ||
|
||
var json = converter.toJson(path); | ||
|
||
PathWithActionHistory deserializedPath = converter.fromJson(json); | ||
|
||
expect(path, equals(deserializedPath)); | ||
}); | ||
|
||
test('Test converter for PathWithActionHistory with two paths', () { | ||
PathWithActionHistory path = createPathWithActionHistory(2); | ||
|
||
var json = converter.toJson(path); | ||
|
||
PathWithActionHistory deserializedPath = converter.fromJson(json); | ||
|
||
expect(path, equals(deserializedPath)); | ||
}); | ||
|
||
test('Test converter for PathWithActionHistory with multiple paths', () { | ||
PathWithActionHistory path = createPathWithActionHistory(10); | ||
|
||
var json = converter.toJson(path); | ||
|
||
PathWithActionHistory deserializedPath = converter.fromJson(json); | ||
|
||
expect(path, equals(deserializedPath)); | ||
}); | ||
} |