-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f53b95
commit 20bc07e
Showing
4 changed files
with
196 additions
and
132 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
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,9 +1,30 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace b64.Exceptions | ||
{ | ||
class InvalidParametersException : Exception | ||
{ | ||
public override string Message => "Invalid parameters detected."; | ||
private readonly List<string> _arguments; | ||
|
||
public InvalidParametersException(List<string> arguments) | ||
{ | ||
_arguments = arguments; | ||
} | ||
public override string Message | ||
{ | ||
get | ||
{ | ||
if (_arguments == null) | ||
{ | ||
return "Invalid parameters detected"; | ||
} | ||
else | ||
{ | ||
return "Invalid parameters detected: " + string.Join(", ", _arguments.Select(x => "{" + x + "}")) + " parameter-count: " + _arguments.Count; | ||
} | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,127 +1,163 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
dotnet build -c Debug | ||
exe="./bin/Debug/net8.0/b64.exe" | ||
|
||
######################################################################## | ||
# Test encoding decoding of a simple string | ||
######################################################################## | ||
test_name="Test 1" | ||
value=test | ||
expectedEncoded=dGVzdA== | ||
|
||
encoded=`$exe encode $value` | ||
if [ "$encoded" != "$expectedEncoded" ]; then | ||
echo "$test_name: Expected encoded value: $expectedEncoded, but have $encoded" | ||
exit 1 | ||
fi | ||
decoded=`$exe decode $encoded` | ||
if [ "$decoded" != "$value" ]; then | ||
echo "$test_name: Expected decoded value: $expected, but have $decoded" | ||
exit 1 | ||
fi | ||
|
||
######################################################################## | ||
# Test encoding decoding from a file with -f | ||
######################################################################## | ||
test_name="Test 2" | ||
value="hello world" | ||
expectedEncoded=aGVsbG8gd29ybGQ= | ||
echo -n $value > test.txt | ||
encoded=`$exe encode -f test.txt` | ||
if [ "$encoded" != "$expectedEncoded" ]; then | ||
echo "$test_name: Expected encoded value: $expectedEncoded, but have $encoded" | ||
exit 1 | ||
fi | ||
`$exe encode -f test.txt > test_encoded.txt` | ||
decoded=`$exe decode -f test_encoded.txt` | ||
if [ "$decoded" != "$value" ]; then | ||
echo "$test_name: Expected decoded value: $expected, but have $decoded" | ||
exit 1 | ||
fi | ||
|
||
rm test.txt | ||
rm test_encoded.txt | ||
|
||
######################################################################## | ||
# Test encoding decoding from a file with < | ||
######################################################################## | ||
test_name="Test 3" | ||
value="hello world" | ||
expectedEncoded=aGVsbG8gd29ybGQ= | ||
echo -n $value > test.txt | ||
encoded=`$exe encode < test.txt` | ||
if [ "$encoded" != "$expectedEncoded" ]; then | ||
echo "$test_name: Expected encoded value: $expectedEncoded, but have $encoded" | ||
exit 1 | ||
fi | ||
`$exe encode -f test.txt > test_encoded.txt` | ||
decoded=`$exe decode < test_encoded.txt` | ||
if [ "$decoded" != "$value" ]; then | ||
echo "$test_name: Expected decoded value: $expected, but have $decoded" | ||
exit 1 | ||
fi | ||
|
||
rm test.txt | ||
rm test_encoded.txt | ||
|
||
######################################################################## | ||
# Test encoding decoding from a file with pipe | ||
######################################################################## | ||
test_name="Test 4" | ||
value="hello world" | ||
expectedEncoded=aGVsbG8gd29ybGQ= | ||
echo -n $value > test.txt | ||
encoded=`cat test.txt | $exe encode` | ||
if [ "$encoded" != "$expectedEncoded" ]; then | ||
echo "$test_name: Expected encoded value: $expectedEncoded, but have $encoded" | ||
exit 1 | ||
fi | ||
`$exe encode -f test.txt > test_encoded.txt` | ||
decoded=`cat test_encoded.txt | $exe decode` | ||
if [ "$decoded" != "$value" ]; then | ||
echo "$test_name: Expected decoded value: $expected, but have $decoded" | ||
exit 1 | ||
fi | ||
|
||
rm test.txt | ||
rm test_encoded.txt | ||
|
||
######################################################################## | ||
# Test url encoding | ||
######################################################################## | ||
test_name="Test 5" | ||
value="https://Hello?a=c&c=d_arg" | ||
expectedEncoded=aHR0cHM6Ly9IZWxsbz9hPWMmYz1kX2FyZw | ||
echo -n $value > test.txt | ||
encoded=`cat test.txt | $exe encode --url` | ||
if [ "$encoded" != "$expectedEncoded" ]; then | ||
echo "$test_name: Expected encoded value: $expectedEncoded, but have $encoded" | ||
exit 1 | ||
fi | ||
`$exe encode -f test.txt > test_encoded.txt` | ||
decoded=`cat test_encoded.txt | $exe decode --url` | ||
if [ "$decoded" != "$value" ]; then | ||
echo "$test_name: Expected decoded value: $expected, but have $decoded" | ||
exit 1 | ||
fi | ||
|
||
rm test.txt | ||
rm test_encoded.txt | ||
|
||
######################################################################## | ||
# Test url encoding back and forth with pipe | ||
######################################################################## | ||
test_name="Test 6" | ||
value="https://Hello?a=c&c=d_arg" | ||
expected=`$exe encode --url $value | $exe decode --url` | ||
|
||
if [ "$expected" != "$value" ]; then | ||
echo "$test_name: Expected encoded value: $expected, but have $value" | ||
exit 1 | ||
fi | ||
|
||
|
||
echo "Tests passed!" | ||
#!/bin/bash | ||
|
||
set -e | ||
#set -o xtrace | ||
|
||
dotnet build -c Debug | ||
|
||
unameOut="$(uname -s)" | ||
case "${unameOut}" in | ||
Linux*) machine=Linux;; | ||
Darwin*) machine=Mac;; | ||
CYGWIN*) machine=Cygwin;; | ||
MINGW*) machine=MinGw;; | ||
MSYS_NT*) machine=Git;; | ||
*) machine="UNKNOWN:${unameOut}" | ||
esac | ||
|
||
echo "Running current tests on $machine" | ||
|
||
exe="./bin/Debug/net8.0/b64.exe" | ||
if [ "$machine" == "Linux" ] || [ "$machine" == "Mac" ]; then | ||
exe="./bin/Debug/net8.0/b64" | ||
else | ||
exe="./bin/Debug/net8.0/b64.exe" | ||
fi | ||
|
||
function assert() { | ||
|
||
testname=$1 | ||
expected=$2 | ||
actual=$3 | ||
|
||
if [ "$expected" != "$actual" ]; then | ||
|
||
echo "$testname: Expected value: $expected, but have $actual" | ||
|
||
echo " _ _ __ _ _ _ "; | ||
echo "| |_ ___ ___| |_ ___ / _| __ _(_) | ___ __| |"; | ||
echo "| __/ _ \/ __| __/ __| | |_ / _\` | | |/ _ \/ _\` |"; | ||
echo "| || __/\__ \ |_\__ \ | _| (_| | | | __/ (_| |"; | ||
echo " \__\___||___/\__|___/ |_| \__,_|_|_|\___|\__,_|"; | ||
echo " "; | ||
|
||
|
||
exit 1 | ||
else | ||
echo "$testname succeeded" | ||
fi | ||
} | ||
|
||
function success() { | ||
echo "All tests passed" | ||
echo | ||
echo " _ _ _ _ "; | ||
echo "| |_ ___ ___| |_ ___ ___ _ _ ___ ___ ___ ___ __| | ___ __| |"; | ||
echo "| __/ _ \/ __| __/ __| / __| | | |/ __/ __/ _ \/ _ \/ _\` |/ _ \/ _\` |"; | ||
echo "| || __/\__ \ |_\__ \ \__ \ |_| | (_| (_| __/ __/ (_| | __/ (_| |"; | ||
echo " \__\___||___/\__|___/ |___/\__,_|\___\___\___|\___|\__,_|\___|\__,_|"; | ||
echo " "; | ||
} | ||
|
||
|
||
######################################################################## | ||
# Test encoding decoding of a simple string | ||
######################################################################## | ||
test_name="Test 1" | ||
value=test_value | ||
expectedEncoded=dGVzdF92YWx1ZQ== | ||
|
||
encoded=`$exe encode $value` | ||
assert "$test_name" "$encoded" "$expectedEncoded" | ||
|
||
decoded=`$exe decode $encoded` | ||
assert "$test_name" "$decoded" "$value" | ||
|
||
######################################################################## | ||
# Test encoding decoding from a file with -f | ||
######################################################################## | ||
test_name="Test 2" | ||
value="hello world" | ||
expectedEncoded=aGVsbG8gd29ybGQ= | ||
echo -n $value > test_input.txt | ||
encoded=`$exe encode -f test_input.txt` | ||
assert "$test_name" "$encoded" "$expectedEncoded" | ||
|
||
`$exe encode -f test_input.txt > test_encoded.txt` | ||
decoded=`$exe decode -f test_encoded.txt` | ||
assert "$test_name" "$decoded" "$value" | ||
|
||
rm test_input.txt | ||
rm test_encoded.txt | ||
|
||
######################################################################## | ||
# Test encoding decoding from a file with < | ||
######################################################################## | ||
test_name="Test 3" | ||
value="hello world" | ||
expectedEncoded=aGVsbG8gd29ybGQ= | ||
echo -n $value > test_input.txt | ||
encoded=`$exe encode < test_input.txt` | ||
assert "$test_name" "$encoded" "$expectedEncoded" | ||
|
||
`$exe encode -f test_input.txt > test_encoded.txt` | ||
decoded=`$exe decode < test_encoded.txt` | ||
assert "$test_name" "$decoded" "$value" | ||
rm test_input.txt | ||
rm test_encoded.txt | ||
|
||
######################################################################## | ||
# Test encoding decoding from a file with pipe | ||
######################################################################## | ||
test_name="Test 4" | ||
value="hello world" | ||
expectedEncoded=aGVsbG8gd29ybGQ= | ||
echo -n $value > test_input.txt | ||
encoded=`cat test_input.txt | $exe encode` | ||
assert "$test_name" "$encoded" "$expectedEncoded" | ||
|
||
`$exe encode -f test_input.txt > test_encoded.txt` | ||
decoded=`cat test_encoded.txt | $exe decode` | ||
assert "$test_name" "$decoded" "$value" | ||
|
||
rm test_input.txt | ||
rm test_encoded.txt | ||
|
||
######################################################################## | ||
# Test url encoding | ||
######################################################################## | ||
test_name="Test 5" | ||
value="https://Hello?a=c&c=d_arg" | ||
expectedEncoded=aHR0cHM6Ly9IZWxsbz9hPWMmYz1kX2FyZw | ||
echo -n $value > test_input.txt | ||
encoded=`cat test_input.txt | $exe encode --url` | ||
assert "$test_name" "$encoded" "$expectedEncoded" | ||
|
||
`$exe encode -f test_input.txt > test_encoded.txt` | ||
decoded=`cat test_encoded.txt | $exe decode --url` | ||
assert "$test_name" "$decoded" "$value" | ||
|
||
rm test_input.txt | ||
rm test_encoded.txt | ||
|
||
######################################################################## | ||
# Test url encoding back and forth with pipe | ||
######################################################################## | ||
test_name="Test 6" | ||
value="https://Hello?a=c&c=d_arg" | ||
expected=`$exe encode --url $value | $exe decode --url` | ||
|
||
assert "$test_name" "$expected" "$value" | ||
|
||
######################################################################## | ||
# Test encoding with whitespace | ||
######################################################################## | ||
test_name="Test 7" | ||
value="https://Hello?a=c&c=d_arg" | ||
expected=`$exe encode --url $value | $exe decode --url ` | ||
|
||
assert "$test_name" "$expected" "$value" | ||
|
||
|
||
success | ||
|