-
Notifications
You must be signed in to change notification settings - Fork 2
Add tethering tests #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ | |
| using Amarula::DBus::G::Connman::Connman; | ||
| using Type = Amarula::DBus::G::Connman::TechProperties::Type; | ||
|
|
||
| constexpr uint32_t WIFI_FREQ_2412_MHZ = 2412; | ||
|
|
||
| TEST(Connman, getTechs) { | ||
| bool called = false; | ||
| { | ||
|
|
@@ -125,6 +127,113 @@ TEST(Connman, ScanWifiTechnology) { | |
| ASSERT_TRUE(called) << "TechnologiesChanged callback was never called"; | ||
| } | ||
|
|
||
| TEST(Connman, SetTetheringOn) { | ||
| bool called = false; | ||
| { | ||
| const ThreadBundle thread_bundle; | ||
| Connman connman; | ||
| const auto manager = connman.manager(); | ||
|
|
||
| manager->onTechnologiesChanged( | ||
| [&called, main_tid = thread_bundle.main_tid, | ||
| loop_tid = thread_bundle.loop_tid](const auto& technologies) { | ||
| ASSERT_FALSE(technologies.empty()) | ||
|
EddyTheCo marked this conversation as resolved.
|
||
| << "No technologies returned"; | ||
|
|
||
| for (const auto& tech : technologies) { | ||
| const auto props = tech->properties(); | ||
| const auto name = props.getName(); | ||
|
|
||
| if (props.getType() == Type::Wifi) { // test only wifi | ||
| std::cout << "Setting tethering properties for " << name | ||
| << "\n"; | ||
| tech->setTetheringIdentifier( | ||
| "AmarulaTestSSID", | ||
| [name, main_tid, loop_tid](bool success) { | ||
| const auto callback_tid = | ||
| std::this_thread::get_id(); | ||
| EXPECT_NE(callback_tid, main_tid); | ||
| EXPECT_NE(callback_tid, loop_tid); | ||
| EXPECT_TRUE(success) | ||
| << "Failed to set tethering identifier for " | ||
| << name; | ||
| }); | ||
| tech->setTetheringPassphrase( | ||
| "AmarulaTestPassphrase", | ||
| [name, main_tid, loop_tid](bool success) { | ||
| const auto callback_tid = | ||
| std::this_thread::get_id(); | ||
| EXPECT_NE(callback_tid, main_tid); | ||
| EXPECT_NE(callback_tid, loop_tid); | ||
| EXPECT_TRUE(success) | ||
| << "Failed to set tethering passphrase for " | ||
| << name; | ||
| }); | ||
|
|
||
| tech->setTetheringFreq( | ||
| WIFI_FREQ_2412_MHZ, | ||
| [name, main_tid, loop_tid](bool success) { | ||
| const auto callback_tid = | ||
| std::this_thread::get_id(); | ||
| EXPECT_NE(callback_tid, main_tid); | ||
| EXPECT_NE(callback_tid, loop_tid); | ||
| EXPECT_TRUE(success) | ||
| << "Failed to set tethering frequency for " | ||
| << name; | ||
| }); | ||
| tech->setTethering(true, [&called, name, main_tid, | ||
| loop_tid](bool success) { | ||
| const auto callback_tid = | ||
| std::this_thread::get_id(); | ||
| EXPECT_NE(callback_tid, main_tid); | ||
| EXPECT_NE(callback_tid, loop_tid); | ||
| EXPECT_TRUE(success) | ||
| << "Failed to set tethering for " << name; | ||
| called = true; | ||
| }); | ||
|
EddyTheCo marked this conversation as resolved.
|
||
| } | ||
| } | ||
| }); | ||
| } | ||
| ASSERT_TRUE(called) << "setTethering callback was never called"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assertion will fail if no Wifi technology is found on the system, as |
||
| } | ||
|
|
||
| TEST(Connman, SetTetheringOff) { | ||
| bool called = false; | ||
| { | ||
| const ThreadBundle thread_bundle; | ||
| Connman connman; | ||
| const auto manager = connman.manager(); | ||
|
|
||
| manager->onTechnologiesChanged( | ||
| [&called, main_tid = thread_bundle.main_tid, | ||
| loop_tid = thread_bundle.loop_tid](const auto& technologies) { | ||
| ASSERT_FALSE(technologies.empty()) | ||
| << "No technologies returned"; | ||
|
|
||
| for (const auto& tech : technologies) { | ||
| const auto props = tech->properties(); | ||
| const auto name = props.getName(); | ||
|
|
||
| if (props.getType() == Type::Wifi) { // test only wifi | ||
| std::cout << "Disable tethering for " << name << "\n"; | ||
| tech->setTethering(false, [&called, name, main_tid, | ||
| loop_tid](bool success) { | ||
| const auto callback_tid = | ||
| std::this_thread::get_id(); | ||
| EXPECT_NE(callback_tid, main_tid); | ||
| EXPECT_NE(callback_tid, loop_tid); | ||
| EXPECT_TRUE(success) | ||
| << "Failed to unset tethering for " << name; | ||
| called = true; | ||
| }); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| ASSERT_TRUE(called) << "setTethering callback was never called"; | ||
| } | ||
|
|
||
| TEST(Connman, PowerOffAllTechnologies) { | ||
| bool called = false; | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.