-
Notifications
You must be signed in to change notification settings - Fork 52
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
Showing
6 changed files
with
195 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/blueutil | ||
|
||
/pkg/ | ||
|
||
build/ | ||
|
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,6 @@ | ||
CFLAGS = -Wall -Wextra -Werror -framework IOBluetooth | ||
|
||
test: blueutil | ||
./test | ||
|
||
.PHONY: test |
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
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 |
---|---|---|
|
@@ -3,5 +3,5 @@ | |
// | ||
|
||
#ifdef __OBJC__ | ||
#import <Foundation/Foundation.h> | ||
#import <IOBluetooth/IOBluetooth.h> | ||
#endif |
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,96 @@ | ||
#!/usr/bin/env bash | ||
|
||
blueutil=./blueutil | ||
errors= | ||
|
||
status=$($blueutil) | ||
trap "{ | ||
$blueutil power $($blueutil power) | ||
$blueutil discoverable $($blueutil discoverable) | ||
echo | ||
if [[ -n \$errors ]]; then | ||
echo -n \"\$errors\" | ||
exit 1 | ||
fi | ||
}" EXIT | ||
|
||
ANSI_BOLD=$(tput bold 2> /dev/null) | ||
ANSI_RED=$(tput setaf 1 2> /dev/null) | ||
ANSI_GREEN=$(tput setaf 2 2> /dev/null) | ||
ANSI_RESET=$(tput sgr0 2> /dev/null) | ||
|
||
success() { | ||
printf "$ANSI_GREEN"."$ANSI_RESET" | ||
} | ||
|
||
failure() { | ||
printf "$ANSI_RED"F"$ANSI_RESET" | ||
errors+="$@"$'\n' | ||
} | ||
|
||
assert_eq() { | ||
[[ $1 == $2 ]] && success || failure "$ANSI_BOLD""$BASH_LINENO""$ANSI_RESET: Expected \"$1\" to eq \"$2\"" | ||
} | ||
|
||
assert_match() { | ||
[[ $1 =~ $2 ]] && success || failure "$ANSI_BOLD""$BASH_LINENO""$ANSI_RESET: Expected \"$1\" to match \"$2\"" | ||
} | ||
|
||
# Init | ||
$blueutil power 1 | ||
$blueutil discoverable 1 | ||
assert_eq "$($blueutil)" $'Power: 1\nDiscoverable: 1' | ||
$blueutil power 0 | ||
$blueutil discoverable 0 | ||
assert_eq "$($blueutil)" $'Power: 0\nDiscoverable: 0' | ||
|
||
# Power | ||
$blueutil power 1 | ||
assert_eq "$($blueutil)" $'Power: 1\nDiscoverable: 0' | ||
|
||
$blueutil power 0 | ||
assert_eq "$($blueutil)" $'Power: 0\nDiscoverable: 0' | ||
|
||
# Power abbreviation | ||
$blueutil p 1 | ||
assert_eq "$($blueutil)" $'Power: 1\nDiscoverable: 0' | ||
|
||
$blueutil p 0 | ||
assert_eq "$($blueutil)" $'Power: 0\nDiscoverable: 0' | ||
|
||
# Discoverable | ||
$blueutil discoverable 1 | ||
assert_eq "$($blueutil)" $'Power: 0\nDiscoverable: 1' | ||
|
||
$blueutil discoverable 0 | ||
assert_eq "$($blueutil)" $'Power: 0\nDiscoverable: 0' | ||
|
||
# Discoverable abbreviation | ||
$blueutil d 1 | ||
assert_eq "$($blueutil)" $'Power: 0\nDiscoverable: 1' | ||
|
||
$blueutil d 0 | ||
assert_eq "$($blueutil)" $'Power: 0\nDiscoverable: 0' | ||
|
||
# Status | ||
assert_eq "$($blueutil status)" 'Status: off' | ||
$blueutil power 1 | ||
assert_eq "$($blueutil status)" 'Status: on' | ||
$blueutil power 0 | ||
assert_eq "$($blueutil status)" 'Status: off' | ||
|
||
# On | ||
$blueutil on | ||
assert_eq "$($blueutil)" $'Power: 1\nDiscoverable: 0' | ||
|
||
# Off | ||
$blueutil off | ||
assert_eq "$($blueutil)" $'Power: 0\nDiscoverable: 0' | ||
|
||
# Help | ||
assert_eq "$($blueutil help)" *'- this help'* | ||
assert_eq "$($blueutil h)" *'- this help'* | ||
|
||
# Version | ||
assert_match "$($blueutil version)" '^[0-9]+\.[0-9]+\.[0-9]+$' | ||
assert_match "$($blueutil v)" '^[0-9]+\.[0-9]+\.[0-9]+$' |