Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6f89f233 authored by Hungming Chen's avatar Hungming Chen
Browse files

ResolverTest: test GetAddrInfoV4_MultiAnswers with any ai_socktype

Add test to query DNS with ai_socktype (0).

Bug: 254192523
Test: atest ResolverTest
Change-Id: If9968422fb104d27a246d1158ed2b814b3ec2a1b
parent c0b025cf
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -891,7 +891,7 @@ TEST_F(ResolverTest, GetAddrInfoV4_MultiAnswers) {
    StartDns(dns, {});
    ASSERT_TRUE(mDnsClient.SetResolversForNetwork());

    const addrinfo hints = {.ai_family = AF_UNSPEC, .ai_socktype = SOCK_DGRAM};
    addrinfo hints = {.ai_family = AF_UNSPEC, .ai_socktype = SOCK_DGRAM};
    ScopedAddrinfo result = safe_getaddrinfo(kHelloExampleCom, nullptr, &hints);
    ASSERT_FALSE(result == nullptr);

@@ -916,6 +916,29 @@ TEST_F(ResolverTest, GetAddrInfoV4_MultiAnswers) {
    EXPECT_THAT(ToStrings(result),
                testing::ElementsAre(kHelloExampleComAddrV4, kHelloExampleComAddrV4_2,
                                     kHelloExampleComAddrV4_3));

    // .ai_socktype will be 0.
    hints = {.ai_family = AF_UNSPEC};
    result = safe_getaddrinfo(kHelloExampleCom, nullptr, &hints);
    ASSERT_FALSE(result == nullptr);

    // The results are sorted in every querying by explore_options and then concatenates all sorted
    // results. resolv_getaddrinfo() calls explore_fqdn() many times by the different
    // explore_options. It means that resolv_rfc6724_sort() only sorts the ordering in the results
    // of each explore_options and concatenates all sorted results into one link list. The address
    // order of the output addrinfo is:
    //   1.2.3.4 (socktype=2, protocol=17) ->
    //   8.8.8.8 (socktype=2, protocol=17) ->
    //   81.117.21.202 (socktype=2, protocol=17) ->
    //   1.2.3.4 (socktype=1, protocol=6) ->
    //   8.8.8.8 (socktype=1, protocol=6) ->
    //   81.117.21.202 (socktype=1, protocol=6)
    //
    // See resolv_getaddrinfo, explore_fqdn and dns_getaddrinfo.
    EXPECT_THAT(ToStrings(result),
                testing::ElementsAre(kHelloExampleComAddrV4, kHelloExampleComAddrV4_2,
                                     kHelloExampleComAddrV4_3, kHelloExampleComAddrV4,
                                     kHelloExampleComAddrV4_2, kHelloExampleComAddrV4_3));
}

TEST_F(ResolverTest, GetAddrInfo_cnames) {