@@ -14,69 +14,81 @@ using namespace Aws::Iot::DeviceClient::Util;
14
14
TEST (LockFile, normalCreation)
15
15
{
16
16
string path = " /run/lock/" ;
17
- string filename = " devicecl.lock" ;
18
- unique_ptr<LockFile> lockFile = unique_ptr<LockFile>(new LockFile{path, " ./aws-iot-device-client" });
17
+ string fileName = " devicecl.lock" ;
18
+ string thingName = " thing" ;
19
+ unique_ptr<LockFile> lockFile = unique_ptr<LockFile>(new LockFile{path, " ./aws-iot-device-client" , thingName});
19
20
20
- ifstream fileIn (path + filename );
21
+ ifstream fileIn (path + fileName );
21
22
ASSERT_TRUE (fileIn);
22
23
23
24
string storedPid;
24
- if (fileIn >> storedPid)
25
+ string storedName;
26
+ if (fileIn >> storedName && fileIn >> storedPid)
25
27
{
28
+ ASSERT_STREQ (thingName.c_str (), storedName.c_str ());
26
29
ASSERT_STREQ (to_string (getpid ()).c_str (), storedPid.c_str ());
27
30
}
28
31
}
29
32
30
33
TEST (LockFile, earlyDeletion)
31
34
{
32
35
string path = " /run/lock/" ;
33
- string filename = " devicecl.lock" ;
34
- unique_ptr<LockFile> lockFile = unique_ptr<LockFile>(new LockFile{path, " test-aws-iot-device-client" });
36
+ string fileName = " devicecl.lock" ;
37
+ string thingName = " thing" ;
38
+ unique_ptr<LockFile> lockFile = unique_ptr<LockFile>(new LockFile{path, " test-aws-iot-device-client" , thingName});
35
39
lockFile.reset ();
36
40
37
- ifstream fileIn (path + filename );
41
+ ifstream fileIn (path + fileName );
38
42
ASSERT_FALSE (fileIn);
39
43
}
40
44
41
45
TEST (LockFile, multipleFiles)
42
46
{
43
47
string path = " /run/lock/" ;
44
- unique_ptr<LockFile> lockFile = unique_ptr<LockFile>(new LockFile{path, " test-aws-iot-device-client" });
48
+ string thingName = " thing" ;
49
+ unique_ptr<LockFile> lockFile = unique_ptr<LockFile>(new LockFile{path, " test-aws-iot-device-client" , thingName});
45
50
46
- EXPECT_THROW (unique_ptr<LockFile>(new LockFile{path, " test-aws-iot-device-client" }), std::runtime_error);
51
+ EXPECT_THROW (unique_ptr<LockFile>(new LockFile{path, " test-aws-iot-device-client" , thingName }), std::runtime_error);
47
52
}
48
53
49
54
TEST (LockFile, multipleFilesWithExtendedPath)
50
55
{
51
56
string path = " /run/lock/" ;
52
- unique_ptr<LockFile> lockFile = unique_ptr<LockFile>(new LockFile{path, " test-aws-iot-device-client" });
57
+ string thingName = " thing" ;
58
+ unique_ptr<LockFile> lockFile = unique_ptr<LockFile>(new LockFile{path, " test-aws-iot-device-client" , thingName});
53
59
54
- EXPECT_THROW (unique_ptr<LockFile>(new LockFile{path, " directory/test-aws-iot-device-client" }), std::runtime_error);
60
+ EXPECT_THROW (
61
+ unique_ptr<LockFile>(new LockFile{path, " directory/test-aws-iot-device-client" , thingName}),
62
+ std::runtime_error);
55
63
}
56
64
57
65
TEST (LockFile, staleFile)
58
66
{
59
67
string path = " /run/lock/" ;
60
- string filename = " devicecl.lock" ;
68
+ string fileName = " devicecl.lock" ;
69
+ string thingName = " thing" ;
61
70
string pidMax;
62
71
ifstream pidFile (" /proc/sys/kernel/pid_max" );
63
72
if (pidFile && pidFile >> pidMax)
64
73
{
65
- ofstream fileOut (path + filename );
74
+ ofstream fileOut (path + fileName );
66
75
if (fileOut)
67
76
{
68
77
fileOut << pidMax;
69
78
}
70
79
fileOut.close ();
71
80
72
- unique_ptr<LockFile> lockFile = unique_ptr<LockFile>(new LockFile{path, " test-aws-iot-device-client" });
81
+ unique_ptr<LockFile> lockFile =
82
+ unique_ptr<LockFile>(new LockFile{path, " test-aws-iot-device-client" , thingName});
73
83
74
- ifstream fileIn (path + filename );
84
+ ifstream fileIn (path + fileName );
75
85
ASSERT_TRUE (fileIn);
76
86
77
87
string storedPid;
78
- if (fileIn >> storedPid)
88
+ string storedName;
89
+ if (fileIn >> storedName && fileIn >> storedPid)
79
90
{
91
+ ASSERT_STREQ (thingName.c_str (), storedName.c_str ());
80
92
ASSERT_STREQ (to_string (getpid ()).c_str (), storedPid.c_str ());
81
93
}
82
94
}
0 commit comments