# HG changeset patch
# User Vladimir Marek <Vladimir.Marek at Sun.COM>
# Date 1221994346 -7200
# Node ID 45f6e802d14b4ab1533c4d4b096b012d78da1159
# Parent 5255d0ea282884117d926b7394140bb3ce404ad1
obtain_sources.ksh test suite
diff --git a/usr/src/tools/test/obtain_sources/bad/bad/file
b/usr/src/tools/test/obtain_sources/bad/bad/file
new file mode 100644
--- /dev/null
+++ b/usr/src/tools/test/obtain_sources/bad/bad/file
@@ -0,0 +1,1 @@
+bad
diff --git a/usr/src/tools/test/obtain_sources/bad/child/file.sha1sum
b/usr/src/tools/test/obtain_sources/bad/child/file.sha1sum
new file mode 100644
--- /dev/null
+++ b/usr/src/tools/test/obtain_sources/bad/child/file.sha1sum
@@ -0,0 +1,1 @@
+50a4e988380c09d290acdab4bd53d24ee7b497df
diff --git a/usr/src/tools/test/obtain_sources/bad/parent/file
b/usr/src/tools/test/obtain_sources/bad/parent/file
new file mode 100644
--- /dev/null
+++ b/usr/src/tools/test/obtain_sources/bad/parent/file
@@ -0,0 +1,1 @@
+something
diff --git a/usr/src/tools/test/obtain_sources/create/file
b/usr/src/tools/test/obtain_sources/create/file
new file mode 100644
--- /dev/null
+++ b/usr/src/tools/test/obtain_sources/create/file
@@ -0,0 +1,1 @@
+already_there
diff --git
a/usr/src/tools/test/obtain_sources/http/Dorfl/WebDesign/dorfl-lcd.gif.sha1sum
b/usr/src/tools/test/obtain_sources/http/Dorfl/WebDesign/dorfl-lcd.gif.sha1sum
new file mode 100644
--- /dev/null
+++
b/usr/src/tools/test/obtain_sources/http/Dorfl/WebDesign/dorfl-lcd.gif.sha1sum
@@ -0,0 +1,1 @@
+23cef7e4ccd095d68b7e0fe53a062c2a2e322118
diff --git a/usr/src/tools/test/obtain_sources/simple/a/file.sha1sum
b/usr/src/tools/test/obtain_sources/simple/a/file.sha1sum
new file mode 100644
--- /dev/null
+++ b/usr/src/tools/test/obtain_sources/simple/a/file.sha1sum
@@ -0,0 +1,1 @@
+da39a3ee5e6b4b0d3255bfef95601890afd80709
diff --git a/usr/src/tools/test/obtain_sources/simple/b/file
b/usr/src/tools/test/obtain_sources/simple/b/file
new file mode 100644
diff --git a/usr/src/tools/test/obtain_sources/test.sh
b/usr/src/tools/test/obtain_sources/test.sh
new file mode 100755
--- /dev/null
+++ b/usr/src/tools/test/obtain_sources/test.sh
@@ -0,0 +1,119 @@
+#!/bin/ksh
+
+# Intercept Ctrl+C and other interrupts
+trap 'exit 1' INT TERM QUIT
+
+# Error handling
+alias err='set -u; trap '"'"'ERR=$?; print -u2 "$0: error on line $LINENO
(\$?=$ERR)"; return $ERR'"'"' ERR'
+err
+
+typeset -x O=$(cd ../..; pwd)/obtain_sources.ksh
+typeset -x SFW_MIRROR_1=""
+
+function announce_test {
+ echo "############################################################"
+ echo "### test no. $1"
+ echo "############################################################"
+}
+
+set -x
+
+# simple mirror from dir to dir
+(
+ err
+ announce_test 1
+
+ cd simple/a
+ rm -f file
+ # Absolute path
+ SFW_MIRROR=$(cd ../b; pwd) $O file
+ rm file
+ # Relative path
+ SFW_MIRROR=file://../b $O file
+ rm file
+)
+
+# mirror from workspace to workspace
+(
+ err
+ announce_test 2
+
+ typeset -x SFW_MIRROR=""
+ typeset -x SFW_MIRROR_2=""
+ cd workspace/child/usr/src
+ rm -f file
+ SFW_MIRROR_1=$(cd ../../../parent; pwd) $O file
+ rm file
+ SFW_MIRROR_1=file://../../../parent $O file
+ rm file
+)
+
+# bad file check, continue with next mirror
+(
+ err
+ announce_test 3
+
+ typeset -x SFW_MIRROR=file://../bad
+ typeset -x SFW_MIRROR_1=file://../parent
+ typeset -x SFW_MIRROR_2=""
+ cd bad/child
+ rm -f file
+ $O file
+ rm file
+)
+
+# bad file check, leave defective file in place if there is not another mirror
+(
+ err
+ announce_test 4
+
+ typeset -x SFW_MIRROR=file://../bad
+ typeset -x SFW_MIRROR_1=""
+ cd bad/child
+ rm -f file
+ $O file && exit 1 || true
+ [ ! -r file ] && {
+ echo file should be left in the directory
+ exit 1
+ } || true
+ rm file
+)
+
+# http
+(
+ err
+ announce_test 5
+
+ cd http/Dorfl/WebDesign
+ typeset -x
SFW_MIRROR=http://dorfl.czech.sun.com/twiki/pub/Dorfl/WebDesign
+ typeset -x SFW_MIRROR_1=""
+ rm -f dorfl-lcd.gif
+ $O dorfl-lcd.gif
+ rm dorfl-lcd.gif
+
+ # XXX mirror http workspace
+ #http://dorfl.czech.sun.com/twiki/pub/Dorfl/WebDesign/dorfl-lcd.gif
+)
+
+# Creating sha1sum
+(
+ err
+ announce_test 6
+
+ cd create
+ typeset -x SFW_MIRROR=/
+ typeset -x SFW_MIRROR_1=""
+ rm -f file.sha1sum
+ $O file && exit 1 || true # We should fail if there is not .sha1sum
+ [ -r file.sha1sum ] && {
+ echo .sha1sum should not be created by default
+ exit 1
+ }
+ $O -C file
+ [ ! -r file.sha1sum ] && {
+ echo .sha1sum should be created if -C is specified
+ exit 1
+ }
+ $O file # now we should succeed
+ rm file.sha1sum
+)
diff --git
a/usr/src/tools/test/obtain_sources/workspace/child/Codemgr_wsdata/empty
b/usr/src/tools/test/obtain_sources/workspace/child/Codemgr_wsdata/empty
new file mode 100644
--- /dev/null
+++ b/usr/src/tools/test/obtain_sources/workspace/child/Codemgr_wsdata/empty
@@ -0,0 +1,1 @@
+empty
diff --git
a/usr/src/tools/test/obtain_sources/workspace/child/usr/src/file.sha1sum
b/usr/src/tools/test/obtain_sources/workspace/child/usr/src/file.sha1sum
new file mode 100644
--- /dev/null
+++ b/usr/src/tools/test/obtain_sources/workspace/child/usr/src/file.sha1sum
@@ -0,0 +1,1 @@
+572c291421cd821a5e821e28766d0bdb719c379d
diff --git
a/usr/src/tools/test/obtain_sources/workspace/parent/Codemgr_wsdata/empty
b/usr/src/tools/test/obtain_sources/workspace/parent/Codemgr_wsdata/empty
new file mode 100644
--- /dev/null
+++ b/usr/src/tools/test/obtain_sources/workspace/parent/Codemgr_wsdata/empty
@@ -0,0 +1,1 @@
+empty
diff --git a/usr/src/tools/test/obtain_sources/workspace/parent/usr/src/file
b/usr/src/tools/test/obtain_sources/workspace/parent/usr/src/file
new file mode 100644
--- /dev/null
+++ b/usr/src/tools/test/obtain_sources/workspace/parent/usr/src/file
@@ -0,0 +1,1 @@
+contents