#!/usr/bin/expect -f
# This file is part of Firejail project
# Copyright (C) 2014-2024 Firejail Authors
# License GPL v2

set timeout 10
spawn $env(SHELL)
match_max 100000
set firstspawn $spawn_id


send -- "rm -f lstesting\r"
sleep 1
send -- "firejail --private --name=test\r"
expect {
	timeout {puts "TESTING ERROR 0\n";exit}
	-re "Child process initialized in \[0-9\]+.\[0-9\]+ ms"
}
sleep 1
send -- "echo my_testing > ~/lstesting\r"
after 100

# ls
spawn $env(SHELL)
send -- "firejail --ls=test ~/.\r"
expect {
	timeout {puts "TESTING ERROR 1\n";exit}
	"lstesting"
}
sleep 1

# get
send -- "firejail --get=test ~/lstesting\r"
sleep 1
send -- "cat lstesting\r"
expect {
	timeout {puts "TESTING ERROR 2n";exit}
	"my_testing"
}
after 100

# put
send -- "echo put_test > ~/lstesting\r"
after 100
send -- "firejail --put=test ~/lstesting ~/lstesting_2\r"
sleep 1

set spawn_id $firstspawn
send -- "ls -al ~\r"
expect {
	timeout {puts "TESTING ERROR 3\n";exit}
	"lstesting_2"
}

after 100
send -- "cat ~/lstesting_2\r"
expect {
	timeout {puts "TESTING ERROR 4\n";exit}
	"put_test"
}
after 100
send -- "exit\r"
sleep 1





send -- "rm -f lstesting\r"

after 100
puts "\nall done\n"
